I am doing backups of a directory with a simple:
cp -R /production/directory /backups/location
Sometimes I need to restore a backup, but doing:
cp -R /backups/location/* /production/directory
or
cp -RT /backups/location /production/directory
has the unwanted (in my case) effect, of keeping files present in /production/directory
but not in the backup, while I want them removed, to get things in the exact same state as when the backup was done.
Is there any magic switch, or other simple command, to perform that, or do I need to manually remove the whole directory first ?
rsync
as followrsync -r --delete-during /backup/location /production/directory
which will scan directories while syncing and put the same content of/backup/location/
to/production/directory
location
with your command, ordirectory
if I add that to source), inside the /production/directory.rsync -r --delete-during /backup/location/ /production/directory