Sync your home directiory with rsync
rsync is a powerful command line utility to protect your data
This video takes a look at the rsync utility, specifically backing up user data in the home directory. (The video is embedded after the article below.)
Rsync, or Remote Sync, is a command-line tool that transfers files and directories to local and remote destinations. Rsync is used for mirroring, performing backups, or migrating data to other servers.
This tool is fast and efficient, copying only the changes from the source and offering customization options.
The scripts referenced on this page are available for download on my Gitlab page.
The basic command
The basic command to backup your home dir is:
rsync -avxP --exclude-from=/path/to/rsync_ignore --delete /home/$USER/ /path/to/your/external/backup/dir
Be sure to change /path/to/rsync_ignore
to where you placed the rsync_ignore file;
be sure to change /path/to/your/external/backup/dir
to where you would like the destination of your synced files to be.
/home/$USER
should work in most cases if you want to back up your entire home directory.
Command line options
I’ve used the following options:
Archive
-a, --archive
This is an important catch-all flag that includes the following options:
`-r, --recursive` recurse into directories
`-l, --links` copy symlinks as symlinks
`-p, --perms` preserve permissions
`-t, --times` preserve modification times
`-g, --group` preserve group
`-o, --owner` preserve owner (super-user only)
`-D` same as `--devices --specials`
`--devices` preserve device files (super-user only)
`--specials` preserve special files
It excludes:
`-H, --hard-links` preserve hard links
`-A, --acls` preserve ACLs (implies -p)
`-X, --xattrs` preserve extended attributes
Verbose
-v --verbose
This option increases the amount of information you are given during the transfer.
One file system
-x, --one-file-system
This tells rsync to avoid crossing a file system boundary when recursing. So basically, it will not follow other mount points to other file systems or partitions.
Partial and progress
-P, --partial --progress
The -P option is equivalent to --partial
and --progress
:
--partial
Keeps a partial file.
--progress
Shows the progress of the transfer.
Delete
--delete
Deletes files in the destination directory if they don’t exist in the source directory. This option is included in the rsync.home.sh
and rsync.home.dryrun.sh
scripts. It is excluded in the rsync.home.nodelete.sh
script.
Dry run
-n, --dry-run
Perform a trial run with no changes made. This option is not included above, though it can be added esially enough. The rsync.home.dryrun.sh file includes it.
Exclude file
--exclude-from=FILE
The command utilizes --exclude-from=/path/to/rsync_ignore
to read a list of directories from the rsync_ignore file.
This file lists each directory you would like to exclude on a separate line. You may comment and uncomment any line at will; and if an entry does not correspond to an existing directory, it will skip it and will not fail.
The --exclude=PATTERN
option can be passed to rsync on the command line, but I have found this to be less reliable than the exclude-file method. It is recommended.
Please see the video below where I go through these commands in detail.
You may view it on YouTube or LBRY
If you found this video useful, please like and subscribe!
Patrons enjoy exclusive benefits for regular contributions:
Or, a one time donation is also very much appreciated: