rsync is a powerful tool that can sync old and new files from one location (local or remote) to another. This utility is known for efficiently transferring updates to a file across a network because it sends only the differences between the source and destination file. It is used in backup and mirroring processes for its fast performance and flexibility.
Although rsync doesn’t have a built-in function to sync only files that are less than 24 hours old, you can couple it with the ‘find’ command in UNIX or Linux to achieve this. Here’s an example:
```
find /source-dir -mtime 0 -exec rsync -Rav {} /destination-dir/ \;
```
In this command, ‘/source-dir’ represents the directory from which you want to sync files, while ‘/destination-dir/’ is the destination directory for the synced files. `-mtime 0` is used to find files modified within the last 24 hours. `-exec` allows you to execute the rsync command on each file found, and `-Rav` includes options for recursive, archive mode, and verbose.
Keep in mind that this does not mirror the directories. It merely copies fresh files that have been changed in the last 24 hours. If you want a complete mirror, including deletion of files in the destination that have been deleted in the source, you have to use rsync alone without the ‘find’ command.
Rsync has many options that you can use according to your specific needs. Here are a few:
- `-a, —archive`: archive mode; equals -rlptgoD (no -H,-A,-X)
- `-r, —recursive`: recurse into directories
- `-v, —verbose`: increase verbosity
- `-u, —update`: skip files that are newer on the receiver
You can find more details and options in the rsync man pages (`man rsync`).
This command is available in Unix or Unix-like systems like Linux, BSD, and MacOS. For Windows, you can use similar software like cwRsync or DeltaCopy, or use the Windows Subsystem for Linux (WSL) for accessing Unix-like functionality.
Remember to carefully review the command before executing to avoid data loss or security issues. Always ensure that you have up-to-date, complete backups of any data that you can’t afford to lose.
Sources:
1. rsync man page https://linux.die.net/man/1/rsync
2. find man page https://linux.die.net/man/1/find
3. Techrepublic guide on syncing only the changed files with rsync https://www.techrepublic.com/article/how-to-sync-only-the-changed-files-with-rsync/
4. Stack Exchange discussion on How to let ‘cp’ command don’t care about files are already existent in destination https://unix.stackexchange.com/questions/71718/how-to-let-cp-command-dont-care-about-files-are-already-existent-in-destination
5. Windows Subsystem for Linux https://docs.microsoft.com/en-us/windows/wsl/