Skip to main content

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.

Related articles

Andrew Fletcher16 Jan 2025
get IP address from terminal OSX
When troubleshooting network issues or configuring devices, knowing your IP address can be essential. Whether you're connected via Wi-Fi, Ethernet, or tethering through a mobile provider, macOS offers powerful built-in tools to quickly identify your IP address. Here's a practical guide tailored to...