rsync: 基本命令和用法

1 说在前面的话

rsync官方网站: https://www.samba.org/ftp/rsync/rsync.html

rsync是可以实现增量备份的工具。配合任务计划,rsync能实现定时或间隔同步,配合inotify或sersync,可以实现触发式的实时同步。

rsync可以实现scp的远程拷贝(rsync不支持远程到远程的拷贝,但scp支持)、cp的本地拷贝、rm删除和"ls -l"显示文件列表等功能。但需要注意的是,rsync的最终目的或者说其原始目的是实现两端主机的文件同步,因此实现的scp/cp/rm等功能仅仅只是同步的辅助手段,且rsync实现这些功能的方式和这些命令是不一样的。事实上,rsync有一套自己的算法,其算法原理以及rsync对算法实现的机制可能比想象中要复杂一些。平时使用rsync实现简单的备份、同步等功能足以,没有多大必要去深究这些原理性的内容。但是想要看懂rsync命令的man文档、使用"-vvvv"分析rsync执行过程,以及实现rsync更强大更完整的功能,没有这些理论知识的支持是绝对不可能实现的。本篇文章将简单介绍rsync的使用方法和它常用的功能。在本篇文章之后的下几篇文章中,将介绍inotify+rsync和sersync,再之后将详细解释rsync相关的原理,其中包括官方技术报告的翻译(即算法原理)、rsync同步的整个过程(也是官方推荐文章的翻译),然后专门使用一篇文章通过示例来详细解释rsync算法原理,最后给出rsync的man文档翻译。希望各位朋友能藉此深入rsync。

回归正题,以下是rsync相关基础内容。

rsync: 中文手册

rsync(1)

名称
rsync - 一个快速、多功能的远程(和本地)文件拷贝工具

摘要
Local: rsync [OPTION…] SRC… [DEST]

   Access via remote shell:
     Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
     Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

   Access via rsync daemon:
     Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
           rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
     Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
           rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST


   当仅有一个SRC或DEST参数时将列出源文件列表而不是复制文件。

描述

AMP: Accelerated Mobile Pages

The AMP Project is an open-source initiative aiming to make the web better for all. The project enables the creation of websites and ads that are consistently fast, beautiful and high-performing across devices and distribution platforms.

AMP pages are built with 3 core components:

AMP HTML ⚡

AMP HTML is a way to build web pages that render with reliable and fast performance. It is our attempt at fixing what many perceive as painfully slow page load times – especially when reading content on the mobile web. AMP HTML is built on existing web technologies; an AMP page will load (quickly) in any modern browser.

You can learn more at ampproject.org including what AMP is, how it works and the importance of validation in AMP. You can also walk through creating an AMP page and read through the reference docs.

Golang Tutorial: What's DefaultServeMux in net/http

craete a HTTPS Server use net/http and route handle function by DefaultServeMux, see code below:

package main

import (
	"net/http"
	"fmt"
	"log"
)

func hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "[%s]: hello!", r.Host)
}

func world(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "[%s]: world!", r.Host)
}

func main() {
	server := http.Server{
		Addr: "127.0.0.1:8080",
	}
	http.HandleFunc("/hello", hello)
	http.HandleFunc("/world", world)

	log.Fatal(server.ListenAndServe())
}

Golang Tutorial: Create HTTPS Server use net/http

It is simple to craete a HTTPS Server use net/http, see code below:

package main

import (
	"net/http"
	"fmt"
)

type SimpleHandler struct {
	Name string
}

func (h *SimpleHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "%s: Hello World!", h.Name)
}

func main() {
	server := http.Server{
		Addr:    "127.0.0.1:8080",
		Handler: &SimpleHandler{Name: "SimpleServer"},
	}
	server.ListenAndServeTLS("cert.pem", "key.pem")
}