Rsync Usage for Backups

Resources

Syntax

  • rsync options source destination
    • source can be a list of files or directories
      • can include userid@host: prefix to copy from a host other then the machine you are on
    • destination can a list or directories
      • can include userid@host: prefix to copy to another host

Options

These are only a few of the most common options

  • -a
    • archive mode, equivalent to -rlptgoD
  • -u
    • updates only new or changed
  • -n
    • dry run - tells you what it will do with the copy
  • --numeric-ids
    • Normally you will not want use this option. Otherwise rsync normally tries to map the group id and userid of a given user if they differ between machines - a default feature most people want. But say you wish to backup a machine over they network in such a way you would restore it latter on - in that case you really do want this option.
  • --delete
    • Note: use with EXTREME CAUTION - this permits deleting any extra files on the destination to make source and destination exactly the same. Example say you delete files on the source machine then run rsync again - normally rsync will just leave those extra files on the destination machine the next time you run it. With this option rsync will also delete any files need to make the source and destination the same. You can use -n to test first if you plan to use this option. Forgetting a trailing slash or typos can do alot of damage!
  • --exclude
    • Used to exclude files when copying.
    • --exclude=".gvfs" .gvfs files can not be copied - they are fuse file system files that exist in a users home directory and are unimportant.
  • -x
    • Don't cross mounted file systems when copying. Normally a linux system has several mounted drives or file systems - this option prevents copying files that exist on other drives. See example below.
  • -H
    • Copy Hard Links
  • --ignore-existing

    • skip updating files that already exist on receiver

  • -info=progress2"
    • Show progress in one line (errors will scroll but not files)

Windows filesystem specific notes

  • -rt should be used instead of *-a" when copying NTFS or FAT32

General notes

Note:

  • When copying someones home directory add --exclude ".gvfs" to eliminate errors
  • If the target of a copy is a directory and it does not yet exist it will be created
  • When you copy files between computers rsync will attempt to map user and group ids if they differ.
    • To prevent this add the option --numeric-ids

Examples

Update remote directory structure to local directory with same name

Update remote directory *contents to local directory

Copy remote user account to local machine

    • rsync -a userid@host:. hostdir
    • Notes: copies the home directory of the user to a local directory called hostdir
    • Warnings: keep in mind that you almost never want to overwrite or merge a remote account into your local account directory - many .file and .directories are note compatible between OS versions and will cause problems.

Update remote file to local file

Clone the root / file system to an external system

    • rsync -a -x -H --info=progress2 --numeric-ids --delete --exclude ".gvfs" / userid@remote_host:pcbackup
    • Notes: make an exact image of the root file system on a remote host. This will exclude mounted file systems like /dev,/sys,proc and other disks that mount on the root file system.

Other Resources

  • See man rsync for more details on command line options
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r7 - 2017-06-30 - MikeGore
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback