Linux Blog

rsync to smb share

Filed under: General Linux — at 4:30 pm on Thursday, September 11, 2008

If you happen to have a SMB share with a lot of disk space laying around, then you may have considered backing up to it. There is more than one methods that you could back up to a SMB share but this article will show how to rsync to a smb share. This blog post assumes that you have successfully set up your SMB share and have installed RSync.

Firstly, you’ll want to mount the directory locally:

[]# mount.cifs //TheLinuxBlog/Share /mnt/Shared/ -o user=TheLinuxBlog

Once you are done you can verify that it is mounted:

[]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
// on /mnt/Shared type cifs (rw,mand)
[] ls /mnt/Shared
[] touch /mnt/Shared/TheLinuxBlogDotCom

Once its mounted, you should be able to write to it, so try touching a file like above. Once you have verified everything is working we’re ready to move onto the rsyncing part.

[]# rsync -avz LocalFiles /mnt/Shared/
building file list ... done
rsync: chown "/mnt/Shared/.LocalFiles/.OfkB4" failed: Permission denied (13)
sent 69440152 bytes  received 42 bytes  957795.78 bytes/sec
total size is 70514910  speedup is 1.02
rsync error: some files could not be transferred (code 23) at main.c(977) [sender=2.6.9]

Using the -avz options in rsync recursively. If you read the rsync man page you will see why you get this error. Basically its because it trys to do it in archive mode, and I don’t have permission to change the permissions. So, if you remove the -a you should not see this error. If you need help with rsync’ing to an smb share, leave a comment and I’ll try to help you out. This wouldn’t be my preferred choice for a backup system, but if its all you have got then go for it!

Man Pages for commands in this post »



Comment by Peter

February 21, 2009 @ 10:34 am

Hi there, I’m trying to use Flyback that uses rsync to backup. I am trying to backup to a samba NAS share that has been locally mounted using the /etc/fstab. It fails with Not a directory errors. When I try to run rsync directly from the command prompt, it does the same. The following is the output of my mount command:
// on /home/peter/public type cifs (rw,mand)
// on /home/peter/media type cifs (rw,mand)
// on /home/peter/NAS_Backup type cifs (rw,mand)
// on /home/peter/NAS_USB type cifs (rw,mand)
// on /home/peter/NAS_Download type cifs (rw,mand)

If I try to touch a file this is what I get:
touch /home/peter/NAS_Backup/test.txt
touch: setting times of `/home/peter/NAS_Backup/test.txt’: Not a directory

Can you help please?

Comment by

March 1, 2009 @ 10:41 pm

@PETER Looks like some sort of permissions problem. See if you can make a file from the NAS server with the permissions of 777, then see if you can touch it to confirm. If you can, then I’d say take another look at your Samba configuration.

Comment by nic

April 5, 2009 @ 10:35 pm

Thanks for the rsync error 13 solution.

You say about rsync “wouldn’t be my preferred choice for a backup system, but if its all you have got then go for it!”

What is your preferred choice of a backup system?

Comment by

April 5, 2009 @ 11:15 pm

Hey Nic,

There are a lot of backup systems, Bacula (
Amanda (
or backuppc ( which would do the job. rsync is really great and if you like it, and it works stick with it. Any backup is better than no backup, which reminds me I need to do one.

Comment by nic

April 6, 2009 @ 9:26 pm

backuppc seems interesting as it is not tape based. I will try it. Thank you for your help.

Comment by Bubba

May 27, 2009 @ 11:11 am

Any recommendations on mirroring CIFS NAS shares?

I was thinking about mounting both shares via mount.cifs and rsync’ing between them. Or alternatively client/server rsync’ing between systems each with one of the two volumes mounted.

Am I crazy?

I’ve had trouble with commercial packages that can’t handle lots of files completing syncs in a short period of time. My NASes are from different vendors, so using vendor specific software is out of the question.

Comment by Owen

May 27, 2009 @ 1:18 pm


So, you’re trying to mirror two NAS devices.

You probably could do it each way. Mounting both shares on one machine via cifs and then rsyncing them would probably be the easiest.
If you’re trying to do it for backup purposes you could use the second way by making a local copy from the first NAS then rsync to the second NAS.

Guess you’d have to do it both ways and see which way is quickest and most reliable. I think the second way would probably be quicker since the data would go Server 1 > Local Copy > Server 2 without the traffic of transferring it to Server 2 whilst grabbing it from one. Effectively slowing down the whole process. Full Speed Download Sync > Local > Full Speed Upload Sync seems like it would be faster initially but the remote CIFS mounts might do better once its synced up. Try it with some smaller directories and see if my theory is correct.

Comment by Bubba

May 27, 2009 @ 2:01 pm

I left out one important item, there’s a decent amount of latency between the NASes. Hence, the client/server approach. Make rsync/rsyncd deal with the latency (and take advantage of compression) not the export/mounted filesystems. Only do that local to the NAS, so the relatively high overhead of the CIFS/SMB protocal isn’t exacerbated by the latency.

I’ve got two distinct file types in the shares. One is a relatively large set of small files (a couple K each) in a deep directory tree. None of these files ever gets deleted (at least not yet). The other set is fewer larger files (a few MB to a couple hundred MB)that get modified frequently.

I’ll probably run multiple clients, so that I can get more parallelism to overcome the latency, but also to attack the different file sets and different and to run them at offset intervals.

Comment by

May 27, 2009 @ 2:08 pm

Sounds like a plan, just be sure to check your mail for any rsync failures as you go along. I’ve found it can fail with many small files, especially with SMB.

Comment by Bubba

June 10, 2009 @ 12:28 pm

I just wanted to drop an update.

This approach has been successful. We made a couple tweeks.

The target shares were mounted with the “noperm” option. Initially, CentOS was trying to enforce permissions in a seemly inconsistent way. By adding noperm, the Windows permissions were inherited properly from those defined for the directory tree by the NAS.

We used SSH as the rsync transport. We used the High Performance Networking version with encryption disabled. We use an encrypted VPN, so that’s redundant and performance impacting.

Thanks so much for your feedback. I’m still surprised I could find a documented solution out there. This situation can’t be the unique can it?

Comment by xky

July 9, 2009 @ 6:42 pm

When i do rsync -avz /source/ /dest it kept appearing a lot of hidden files like .abc.pdf.167RAI.

I delete them using the rsync option: –delete-after
And when i rsync again the damn files appears in my drive!

Is this normal?

Thx a lot

Comment by Owen

July 21, 2009 @ 11:21 am

@XKY I have never ran into this issue before, have you checked the source and destination files for these files and folders beforehand? I’d assume you have.

Comment by Noah

November 11, 2009 @ 6:21 pm

You might, depending on your distribution, need to add “wins” after “dns” in /etc/nsswitch.conf so that the name of the Samba server is resolved.

Comment by Schedule

October 30, 2010 @ 12:14 am

Maybe you should make changes to the webpage subject The Linux Blog » rsync to smb share to more generic for your subject you create. I loved the the writing all the same.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>