"Managing Files Using Bash and Z Shell" course by Mateo Prigl at Pluralsight
Backing Up with Rsync
If you need to keep two directories synchronized, you can use the rsync
command. It works just like cp but it has more options.
You also need to add r when you want to sync directories. If you end the
directory name with slash, only the contents will be copied over, not the
directory itself.
Use the a option to copy files and directories and also keep their modification
time and other details.
$ rsync -a original_dir/ backup/
rsync will synchronize files incrementaly. That means that it will not copy all of
the files if it doesn't have to. It will copy only those files that are missing from
the target directory.
You can use the n dry-run option to prevent the synchronization so that you
can see which files the rsync plans to copy.
Use this option with the v verbose option, which will print out what the
command is doing in the background.
There is also a --delete option you can add. rsync will then delte all of the files
in the backup directory which don't exist in the directory you are trying to back
up (the one from the first argument).
1/1 © Copyright 2020 by Pluralsight