Copy files between computers

Let's say you have a server you want to backup (or copy) on your home machine, for instance after an OS update failure. You can copy files using scp, but if, for some reasons, your Internet connexion fails, scp will download everything again. You want something more reliable, and easier to use. Here's come rsync.

This command will backup folder/to/backup on your server on the local folder ~/destination/of/backup:

rsync -v --progress --stats --human-readable -a -e ssh --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/home/*","/lost+found"} user@server.ip.or.url:/folder/to/backup ~/destination/of/backup     
  • a to add recursivity and a bunch of other stuff
  • --progress displays the progression of the transfer (on a per file basis)
  • --stats provides file size, and so on
  • --human-readable formats information in human readable format
  • -r is needed if you want to sync/backup/copy folders (it tells rsync to sync files recursively)
  • -e ssh tells rsync to connect to one (or two) servers though ssh (so with this command, you can actually sync two remote servers from your local machine)
  • --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/home/*","/lost+found"} is self-explanatory. If you perform a full copy of your server, you probably don't want those files on your local machine
  • -v is for verbose, which means rsync will provide you the full list of which files are copied and are not

Another drawback of scp compared to rsync is that scp is painfully slow when asked to copy a large amount of small files. rsync seems more efficient in this respect.

More stuff on doing backup with rsync here.

Use this to copy a local file to a remote server:

rsync -v --progress --stats --human-readable -a -e ssh ~/file/to/transfer.ext user@server.ip.or.url:/folder/where/to/copy/the/file      

See above for details about the options.

Notice that if for some reason, the connection is interrupted, rsync will resume where it stopped. In other words, if you have a large file to copy, use this.

Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.
  • Last modified: 7 months ago
  • by Olivier Simard-Casanova