I had generated a backup of key directories on the server - see Create a Ubuntu backup shell script. With a backup in hand, now it was time to test how to unpack a backup and overwrite the directories.
First I unpacked the backup to a temporary directory tmp-cc.
Now I wanted to replace several of the directories on the server. Starting with home, var and etc. But what is an efficient method to overwrite a directory? Also removing any directories that aren't in the copied version. Initially, I tried
cp -rlf tmp-cc/home/ home
And other varying forms of cp and mv. None had the impact I was seeking. Instead, I began to investigate rsync
rsync -a --delete tmp-cc/home/ home/
-a | is 'archive mode', which copies faithfully files in foo/ to bar/ |
--delete | removes extra files not in tmp-cc/home/ from home/ as well, ensuring home/ ends up identical |
-vh | verbose and human-readable |
If you want to see what it's doing, then add -vh as noted in the table above
Note: the slash after foo is required, otherwise rsync will copy tmp-cc/home/ to home/home/ rather than overwriting home/ itself.