Handy Linux backup scripts and commands

Almost every Linux distribution worth its salt comes with rsync and lftp – powerful backup and transfer tools that can help you to keep your important data safe. But what if you don’t have time to fiddle with multiple settings? No problem. Here are a couple of rsync and lftp command samples you can use to create your own backup scripts in a matter of minutes. Let’s start with rsync:

rsync --verbose --progress --recursive --times --perms --compress --delete /path/to/source/ /path/to/target

Replace /path/to/source/ with the actual path to the source directory and /path/to/target with the path to the directory where you want to back up the source, and your back up command is ready to go. While you can perform backup by running the command manually, a better solution is to save it as bash script. This can be especially useful if you have to back up multiple directories. To create a script, make a new text file and type #!/bin/bash in the first line followed by the desired rsync commands. For example, here is what a bash script that backs up Firefox and Thunderbird profiles looks like:

#!/bin/bash
rsync --verbose --progress --recursive --times --perms --compress --delete /home/user/.mozilla /path/to/target
rsync --verbose --progress --recursive --times --perms --compress --delete /home/dmpop/.thunderbird /path/to/target

Save the file with the .sh extension (e.g. mozillabackup.sh), and the script is ready. Now you can perform backup by simply running the sh mozillabackup.sh command.

If you want to back up your files on a remote FTP server, you might want to use lftp. By default, lftp considers the current directory as a source, so before you do anything, switch to the directory you want to back up using the cd command. You can then connect to your FTP server using the following command:

lftp -u user,password ftpserver/path/to/target

Replace “user” and “password” with your FTP credentials and use the actual FTP server. Once connected, you can back up the files in the current directory using the mirror command:

mirror -R --delete --only-newer --verbose

If you want to exclude particular files or directories from being backed up, use the exclude option. In the following example, the backup skips the tmp directory.

mirror -R --delete --only-newer --verbose --exclude tmp

Related articles:

PageDateUserTags
Handy Linux backup scripts and commands 2007/09/20 11:14 Dmitri Popov , ,
Quick and easy FTP backup with lftp 2008/01/09 12:31 Dmitri Popov ,
Sync everything with Conduit 2008/06/18 00:01 Dmitri Popov , ,
Toucan: versatile portable backup utility 2007/08/06 15:28 Dmitri Popov , , ,
Using Unison to synchronize data on a USB stick 2007/08/09 12:32 Dmitri Popov , , ,

AddThis Social Bookmark Button

 
tips/backupscripts.txt · Last modified: 2008/06/01 16:16 (external edit)
 
OpenOffice.org user? Read the Writer for Writers and Advanced Users book
GNU FDL OpenOffice.org Powered by DokuWiki