This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Tools & Utilities

Instant backups with smbmount and grsync

By Dmitri Popov on August 01, 2007 (9:00:00 AM)

Share    Print    Comments   

Need a simple yet effective way to back up your laptop or desktop machine to a network-attached storage device or a network hard disk running Samba? Using Samba's smbmount utility and the grsync backup tool, you can set up a backup system that is both reliable and straightforward in use. And since both programs are available as packages for most Linux distributions, you don't have to get your hands dirty compiling from source code and fiddling with settings.

Before you get started, check whether the smbfs package is installed on your machine. While many Linux distributions come with smbfs preinstalled, on other distros you have to install the package. On a Debian-based system you can use either the Synaptic package manager or the sudo apt-get install smbfs command.

With smbfs installed, you can mount a Samba share using smbmount, a clever little tool that mounts a Samba share to your local file system as if it were a directory on your hard disk. By default, you can use smbmount only as root, so if you want to be able to run it as a non-root user, you have to change its permissions by using the following command:

  chmod u+s /usr/bin/smbmnt

Next, you have to create a mount point -- a directory where the Samba share will appear. For example, you can create the sambashare folder in your home directory. You can then mount the Samba share into the created sambashare directory using a command like:

  smbmount //smb/share /home/user/sambashare -o username=smbusername,password=smbpassword

The //smb/share part refers to the actual path to the Samba share -- for example, //192.168.1.7/Documents. The second path points to the mount point on your local machine that you created earlier. While you can specify the user name and the password directly in the command, that's not especially secure, since they are then recorded in the .bash_history file. For better security, you might want to save credentials in a text file (e.g. smb_credentials) as follows:

  username = smbusername
password = smbpassword

You can then point smbmnt to the credentials file:

  smbmount //smb/share /home/user/sambashare -o credentials=/home/user/smb_credentials

Once the Samba share has been mounted, you can use it as a place to which to back up local files and directories. For that you need rsync, a popular command-line synchronization and backup tool. If you haven't tried rsync, take a look at Back up like an expert with rsync, which will help you to get started. As an example, here is the command I use on my machine to back up Firefox settings:

  rsync --verbose --progress --recursive --times --perms --compress --delete /home/dmpop/.mozilla /home/dmpop/smbshare/backup/

Figure 1 If working from the command line doesn't tickle your fancy, try grsync, a graphical front end to rsync that makes the backup process simple. It also allows you to create and manage multiple backup profiles (called sessions). To create a new profile, press the program's Add button, give the profile a name, and press OK. You can then enter the paths to the source and destination directories and specify the desired options by ticking check boxes. If you are not sure what each check box does, hover the mouse over it to see a pop-up window with a brief explanation.

That's all there is to it. Once you have the basic backup system in place, you can improve it. For example, you can create a simple bash script that runs the specified rsync commands, and you can schedule backups using tools like KCron.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Share    Print    Comments   

Comments

on Instant backups with smbmount and grsync

Note: Comments are owned by the poster. We are not responsible for their content.

Instant backups with smbmount and grsync

Posted by: Anonymous [ip: 84.9.2.245] on August 01, 2007 11:22 AM
Rsync only does one-way synchronisation, i.e. the file is copied from A to B, overwriting the B copy. In the context of this article, this is probably fine since you always want the new version on the laptop to overwrite the old version on the backup server (though it would be better if the backup server had proper version control, so that you could also recover old versions).

But if you want to keep a laptop synchronised with a desktop machine, where files may be modified on either machine, you might like to check out "unison". It uses the rsync protocol to transfer files, but does full two-way synchronisation. I.e. when A and B are synchronised, A overwrites B if A has been modified, whereas B overwrites A if B has been modified (if both have been modified, unison asks you what it should do, or whether it should skip this file, and lets you view the files, diff them, etc.). It's possible to partially mock this up using rsync, but it's error prone and unison does it much better, so why not use it? Unison comes with both command-line and graphical interfaces, and works on Linux, Mac OS X, Windows, Solaris... (and can synchronise files between them).

#

Instant backups with smbmount and grsync

Posted by: Anonymous [ip: 67.88.249.34] on August 01, 2007 05:31 PM
Did not know about Grsync and I have been using rsync for years. A wonderful program!

#

Instant backups with smbmount and grsync

Posted by: Anonymous [ip: 146.114.69.57] on August 01, 2007 05:33 PM
Why not just use rsync to copy to the remote machine?
rsync --verbose --progress --recursive --times --perms --compress --delete /home/dmpop/.mozilla [username]@[server]:/home/dmpop/smbshare/backup/

Even better, use an RSA key to automate the credentials.

#

Instant backups with smbmount and grsync in reverse

Posted by: Anonymous [ip: 213.120.81.205] on August 02, 2007 08:44 AM
Anyone know how to backup a windows PC to a linux box over the internet using something like SSH/rsync?

#

Re: Instant backups with smbmount and grsync in reverse

Posted by: Anonymous [ip: 80.80.22.6] on August 02, 2007 09:19 AM
"Anyone know how to backup a windows PC to a linux box over the internet using something like SSH/rsync?"

You could use Unison, but maybe that's not automatic enough.

#

Instant backups with smbmount and grsync

Posted by: Anonymous [ip: 81.192.43.43] on August 02, 2007 08:47 AM
Thank you, that was a quick & easy to understand guide

#

Instant backups with smbmount and grsync

Posted by: Anonymous [ip: 64.0.134.98] on August 04, 2007 02:28 PM
unison rocks. it does ssh also. definitely the way to go for backing up and keeping synchronized.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya