How can I use rsync to sync only new and updated files?
Asked by
EpicGamer42
I'm trying to sync my local drive with an external hard drive using rsync and I want it to only copy new and updated files. Additionally, I need it to remove files from the destination if they've been removed from the source. I initially used the `-avP` command but it seems to copy everything again, which makes the process much longer than I would like. I'm using Debian 13 for this backup. How should I structure my command to achieve the desired incremental backup?
Answers
Make sure you use the `-u` option as well, which tells rsync to skip files that are newer on the destination. It's a good way to ensure you're only syncing what's necessary.
Reply to this answer
You can simplify your command to `rsync -av --delete /path/to/source/ /path/to/destination/`. This way, it will only copy new or updated files from the source and also remove files from the destination that no longer exist in the source.
Reply to this answer
Just a tip: If you have a large amount of data to transfer, including exclusions for items like your system's trash can can save you some time. For example, you might do `rsync -avhsP --delete --exclude=.Trash-1000 /mnt/media/ acer3:/mnt/media/`.
Reply to this answer
If you're seeing everything copied again, it might be due to differences in file permissions or timestamps. Use the same path formatting on both sides, including trailing slashes. Try `rsync -avhsP --delete /source/path/ /destination/path/` and consider running it with a dry-run using the `--dry-run` option first to verify it will do what you expect.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions