Advertisement

Advertisement

Site Search

Latest Forum Posts

Backing Up Your Linux

Article Image
Print This ArticlePrint This Article
Date: August 27, 2007
Author(s): Rob Williams

Backing up your computer is important. Don't be the sucker who loses important files and has to deal with it afterwards! In this how-to, you will learn about using rsync and lftp, writing your own scripts and adding them to crontab and of course, backing up to your external storage, NAS and also a remote server running Linux.

Introduction, rsync Basics

Although I don't like to admit it, I have screwed up many times since I first began using computers. My first big, "Oh shi!" was when I was about 8 years old, goofing around on our trusty 286 with monochrome monitor. DOS was a new world to me, and I quickly found out that format c: was NOT the proper command for deleting contents off a floppy disk. What a fun day that was...

Luckily, much has changed since then, but even in recent memory I can recall careless mistakes I've made, which have led to lost files. But, no longer. I made it a goal to keep perfect backups of my data so that I don't suffer such a fate again, and I highly recommend everyone reading this article to do the same. It's one of the worst feelings when you realize you lost a file that you cannot get back... so don't let something like that happen to you.

Today's article will be focusing on just that... backing up your files in Linux. This article will not be focusing on backing up your entire system, although I'm sure that you could do such a thing with some of the tips provided here. That's up to you to test out if you are interested. Instead, we will be focusing on backing up your personal data, anything you feel you want to keep safe.

There are many different mediums that you can back up to, but we are going to take a look at the three most popular and go through the entire setup process of each: 1) Backing up to external storage; 2) Backing up to a Network-Attached-Storage (NAS) and 3) Backing up to a remote server running Linux. On this first page, we are going to delve into the wonderful tool that is rsync, and give examples for you to edit and test out for yourself.

Why rsync?

"Why not rsync?" might be the better question. Essentially, rsync is a file synchronization application that will match the target with a source, with proper permissions retained. The beauty is that its usage is not simply limited to the PC you are on, but it can access remote servers via RSH or SSH.

As an example, let's use the scenario that you want to back up your top secret documents folder to a thumb drive. When given the "OK", rsync will copy all of the files to your thumb drive, making sure to retain the correct permissions while verifying that all of the files match. If you update a file and run rsync again, it will update the file to the storage you specify... simple as that. Though it's not immediately user-friendly, given its command-line-based nature, once you gain basic knowledge of how it works, you will wonder how you went so long without using it.

The important thing to note is that there are numerous methods of backing up your files and system under Linux and that I am only touching the basics. This tutorial is based off of what I personally rely on, on a daily basis, and are also techniques that can be easily implemented into your own system.

How To Use rsync

As mentioned above, rsync is a very powerful application and we can't possibly exhaust all of the possibilities with this article. We will touch the basics however, with hope that you will finish reading and find yourself more knowledgeable overall and raring to go. Once you set up a cool backup scheme, it will mimic commercial software for Windows. While rsync is not too pretty too look at, it's just as effective, if not more so, and free!

First, the absolute basic. Copying one folder to another:

rsync -r /home/techgage/arch /home/techgage/bintoo

That will copy the folder with simple application, without that much care to preservation of permissions/owners/etc. To make exact duplicates, we can add the -a switch.

rsync -a /home/techgage/centos /home/techgage/damnsmall

To retain ALL owners correctly though, it's best to do all of this in superuser mode. You are obviously not going to properly copy root files without being root. To increase verbosity, add a -v. That will increase the output and give interesting information, such as overall speed and total size.

rsync -av /home/techgage/elive /home/techgage/fedora

Many people who back up a folder or sets of folders want both the target and source to be identical. However, rsync's default method is simply to overwrite what's there with newer files, ignoring the fact if there are files on the target device that are no longer on the source. eg: You back up your home folder, but deleted a bunch of files off your desktop. You obviously want them gone off the backup as well, and luckily, that is easy to take care of.

rsync -av --delete /home/techgage/gentoo /home/techgage/helix

If you are new to rsync, you might be thinking, "Is that all there is to it??" The answer is yes, a very big yes. ;-) Though all of these examples look, and are, simple, there are many things that you could do without even leaving your seat. Imagine backing up one Windows machine to another (aka your moms and your sisters).

rsync -av --delete /mnt/virus1 /mnt/virus2

The above example would assume that each computer is properly mounted, via Samba, a technique we tackle on page three of this article. What about backing up your server or another Linux machine in your house? Time to bring SSH into the picture! This assumes that each computer has SSH installed and that the source machine has an SSH server running. If it's not, it should be as easy as running /etc/init.d/sshd start.

rsync -av --delete -e ssh root@192.168.1.5:/home/techgage/knoppix /home/techgage/linux-gamers
(rsync -av --delete -e ssh root@targetcomputersipaddress:/remotefolder /localfolder)

SSH in itself offers a lot of potential, as well. If you have multiple servers and need to duplicate a folder from one to the other... just SSH in and run rsync. The possibilities are near-endless.

This is about as much of rsync as we will tackle, but don't hesitate to check out man rsync for a full options list and other examples. That's not as far as our samples go though, as we have many scripts on the last page of this article. For now, let's move right into backing up to an external storage device.


Forward >>