Backup old files before overwriting in rsync

By default, rsync overrides old files in the destination server/folder. To resolve this use the –backup flag in rsync.

rsync -a –backup –backup-dir=”/src-old-files” /usr/src/ root@85.17.219.154:/src-backup/

The above rsync command will copy files from local server /usr/src to root@85.17.219.154:/src-backup/. If some files are overwritten in root@85.17.219.154:/src-backup/, these will be backed up in root@85.17.219.154:/src-old-files first before they are being overwritten.

Leave a Reply