Go to ...

Techpository

A Better Technical Repository

RSS Feed

Linux: Using rsync with a samba/smb/cifs share


Make a mount point:

mkdir /mnt/share

Then, mount your smb share:

mount.cifs //192.168.0.6/sharename /mnt/share -o user=username

It’ll prompt you for a password (you want to stay away from typing passwords within commands when you can!)

Verify it’s mounted by using the mount command:

mount
//192.168.0.6/sharename on /mnt/share type cifs (rw)

Want to do it automagically at every boot? Add it to /etc/fstab:

//192.168.0.6/share    /mnt/share        smbfs    username=rob,password=SuPeRdUpEr 0 0

Now you can rsync stuff to it – let’s rsync rob’s home directory into a dir called ‘homedir’:

rsync -avz /home/rob/ /mnt/share/homedir/

Now, if you really want to get fancy and feel all backed up all the time, add an rsync to crontab!

crontab -e

And add your rsync line to go every night at 2am (or whenever) w/o emailing root anything.

* 2 * * * /usr/bin/rsync -avz /home/rob/ /mnt/share/homedir/ >/dev/null 2>&1

One thing to make sure of though – ensure that your NAS will always come up under that same ip address or your system won’t be able to mount it – and you’ll be rsyncing your home directory into your /mnt/share/homedir on your local system.

By: Rob