February 19

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


Copyright 2021. All rights reserved.

Posted February 19, 2014 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B