Using smb and rsync to backup

I needed a script to backup a workfolder to a Windows network server. I wrote this perl script that can be triggered using cron. First create a mount point. I used /smb/public. So to do so in two steps, mkdir /smb, then mkdir /smb/public. I put my scripts in ~/bin. Put this perl script below in ~/bin. Set the $folderToBackup variable. You’ll need to set the smb parameters. Fill in the username, password and share that you need to backup to. On your command line change directory to the ~/bin folder cd ~/bin. Then run it by typing this on the command line ./backupFolder.pl

#! /usr/bin/perl -w
##################

my $folderToBackup = "/Users/bradrice/Documents";

##########################

#main package subroutines

sub mountDrive {
system('mount_smbfs //bradrice:password@SMBSERVER/SMBSHARE /smb/public');
}

sub copyFiles {
system("rsync -auv $folderToBackup /smb/public/Documents/");
}

sub unmountDrive {
system("umount /smb/public");
}

mountDrive();
copyFiles();
unmountDrive();

I changed my rsync command to this: system("rsync -auv –modify-window=1 $folderToBackup /smb/public/BRice/"); in order to make my snyc not copy all the files every time. Apparently the windows machine sends back a different time format. See the rsync manual for that option. If this is run as a cron, the -v option which means verbose should be changed to -q for quiet.

Leave a Reply

You must be logged in to post a comment.