Using rsync to update a samba share from windows

I have used this technique to migrate a windows fileserver to a ubuntu samba server.  Rsync is a brilliant tool that uses a delta-algorithm to transfer files. This makes it easy to keep folders synchronized across networks.

First I mounted the the windows share on my linux box using this command. Note the iocharset and codepage. These are to keep my Norwegian characters normal :)

mount -t cifs  //winserv/share /mount_dir -o username=johndoe,password=blabla,iocharset=utf8,codepage=cp850

Then, I used rsync to copy them into the new folders. Note the exclude, this is because /exports is a NetApp file system mounted via NFS, and I don’t want to include these backup dir’s into them mess.

rsync --verbose  --progress --stats --recursive --times --perms --links --delete --exclude '.snapshot' /source_dir /dest_dir

Voila!

Ps. Add the option –dry-run to have  a preview of what’s to come.

Find & copy

I had a need to get find a few files that had been added or modified within the last 14 days and make a backup of those files.
Not to big of a problem, except that they were hidden amongst 90,000+ other files.

Find to the rescue! The operation comes in two parts.

First I need to create a mirror of the directory structure.

find /exports/ -mtime -14 -type d -exec mkdir -p /root/backup/{} \;

Then we backup the files

find /exports/ -mtime -14 -type f -exec cp -pf '{}' '/root/backup/{}' \;
Source:
http://linux.dsplabs.com.au/find-replicate-mirror-copy-complex-directory-and-file-structure-using-hard-links-p44/