https://www.nicovs.be/rsync-files-younger-or-older-than/
Finding files younger than 31 days is performed like this:
1
|
find /path/to/folder -type f -mtime -31
|
Rsyncing all files from a folder is pretty easy too:
1
|
rsync -avhR /path/to/folder/* user@remote_ip:/path/to/destination/folder
|
Now, if you would like to rsync only the filers younger thn 31 days from your source folder, you can combine rsync and find in this way:
1
|
rsync -Ravh `find /path/to/folder/ -type f -mtime -31` user@remote_ip:/path/to/destination/folder
|
However… this is not 100 working as intended… This will skip filename with spaces, as the space are not escaped during the rsync…
The solution for this is to split the one liner above into 2 seperate commands again:
1) perform the find, and write the output to a tempfile:
1
|
find /path/to/folder -type f -mtime -31 > /tmp/rsyncfiles
|
2) perform the rsync with the –from-files parameter:
(do not forget the . in the command to declare a ‘source dir’)
1
|
rsync -Ravh --files-from=/tmp/rsyncfiles / user@remote_ip:/path/to/destination/folder
|
Remark: When using relative paths, you could/should change the /path/to/folder to path/to/folder and put a . instead of a / in your rsync command
E.g. like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
cd /var
find . -mtime -6 > /tmp/rsyncfiles
rsync -Ravh --files-from=/tmp/rsyncfiles . root@www.someserver.com:/root/backup --dry-run
building file list ... done
./
locatedb.n
cache/
cron/
empty/
lib/
log/
log/setup.log
log/setup.log.full
run/
run/utmp
tmp/
sent 372 bytes received 48 bytes 280.00 bytes/sec
|
No Comments