Tag Archives: copy

Rsync files younger or older than

Today I needed to copy all files from a certain folder, but younger than 1 month  to a remote machine.

I knew how to use find of course… and rsync is pretty easy too… Combining these 2 needs some explanation:

Finding files younger than 31 days is performed like this:

Rsyncing all files from a folder is pretty easy too:

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:

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:

2) perform the rsync with the –from-files parameter:

(do not forget the . in the command to declare a ‘source dir’)

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:

Using Robocopy to copy backups and maintain file retention.

I am using Tara’s excellent MsSQL Backup script to backup my SQL databases. This is an excellent way to backup SQL DB’s if you have an SQL Express version installed. Heck,   I even use this when higher SQL versions are installed (with maintenance plan possibilities and stuff).
On top of that, I needed a script which was able to:
– Move my MsSQL BAK files from a local disk to a network path. This is because the backup script does not allow to backup to UNC paths.
– Clean up older backups on the destination directory.

I found (actually, I already knew) that Robocopy was a very nifty tool to do things like this.

My Howto:

Prepare your destination (backup) drive on your network by creating 2 ‘dummy dir’s:

  • 1 actual backup destination folder on your remote fileserver (eg \\bck_svr\SQL_Backup)
  • 1 directory to move your older files too ( eg \\bck_svr\delete)
  • 1 always directory that acts as a ‘delete mirror’ ( eg \\bck_svr\EMPTY)

After that, just download and install the Resource Kit Tools, and create a BAT script that looks like: