LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-09-2006, 12:05 AM   #1
chu2654
LQ Newbie
 
Registered: Nov 2006
Posts: 15

Rep: Reputation: 0
How can I backup a linux system ?


Hello,
In windows, we can use GHOST. But in linux, how can I backup system ?
 
Old 11-09-2006, 12:34 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Ghost would be used to backup a partition in case you need to re-install. In Linux you can do the same thing by using the humble "dd" program. Because as root you have access to the drive or partition itself and because in Linux "Everything is a file" you don't need a fancy program to make an image of a drive or partition.

If you want, you can pipe the output through gzip or bzip2 to add compression. The amount of compression you will get depends on how full the drive is. A new install that uses 20% of a partition will compress to around 20% of the size of an uncompressed image. However, my experience may be due to the drive being new. If you are using an external USB drive or SMB share to store the image, remember that there is a 2 GB limit. You can use the "split" program to break up the image into consecutively numbered pieces.

Restoring would be as simple as using the "cat" program with a wild card to reassemble the pieces and piping "|" the output through gunzip (or combine the last two with zcat) or bunzip2 and piping the output through another dd command where you have the option "of=/dev/<device>" instead of "if=/dev/<device>".

For routine backups, backup the files instead of the drive image. This is true for windows and Linux. You can use tar or star or dar for that. I like the dar program and the KDE front end "kdar". It allows you to make a full backup and store it on DVD discs, and includes a cataloging front end for backup file selection and restoring.

You could also simply use K3B to backup files and directories to DISC. However this works best for user documents, then for system files, that may have odd names and permissions or be links to files elsewhere. However, if you want to backup a directory that contains MP3s or source tarballs, this solution works great. After you are done, you can save the selections. The resultant .K3B file is a zip archive of two files, one of them called maindata.xml which contains a list of the files that you backed up to CDROM or DVD.

I use:
Code:
sed -e '/^<url>/d' -e 's/<url>\(.*\)<\/url>/\1/'  \
    -e 's/\&amp;/\&/g' -e 's/\&lt;/</g' -e 's/\&gt;/>/g' maindata |
tr '\n' '\000' | xargs -0 -L 100 rm
to remove the files that I have backed up. ( note: I'm typing this in from memory, so please test the output of the sed command before using it to delete your backed up files. ) This deletes the files of what I just backed up with K3b. The last three sed replacements are because XML replaces the "&", "<", and ">" characters with "&amp;", "&lt;" and "&gt;" respectively. It does this because these characters are reserved for markup. The sed test removes xml lines dealing with the K3B configuration, leaving the filename entries. The second sed command removes the <url> and </url> tags, leaving a list of files. The "tr" command replaces returns with zero's. This is similar to using the -print0 option of the find command and and cooresponding -0 option of xargs. This allows you to have spaces in filenames.

Good Luck!

Last edited by jschiwal; 11-09-2006 at 12:46 AM.
 
Old 11-09-2006, 12:42 AM   #3
meetscott
Samhain Slackbuild Maintainer
 
Registered: Sep 2004
Location: Phoenix, AZ, USA
Distribution: Slackware
Posts: 411

Rep: Reputation: 43
There are a ton of ways to backup your Linux system. You need to decide what you want to back up and what medium you are going to use. Your distro makes a good backup for most of your stuff. If you're really disciplined, you really should only need to backup /etc, /usr/local, and /home. If you start messing with other parts of the system you may have to look at backing up more. I keep a step by step set up sheet if I ever need to start from scratch along with backups;-)

Some things to look into are:
- tar (tape archive)
- cpio
- gzip
- bzip

You can also leverage the "find" utility to make incremental backups. Okay, so what do I do? I set up a raid 1 server and another system and they rsync each other every night at 3am. Only the parts that "make sense" are kept in sync. Aside from that I backup system files I've changed in a script off to another location. I add another file to the list whenever I make a change and rerun the script.

My point is, decide what you're backing up and what you want to do with it. I require another system to stay in sync in case the primary dies, I can bring another one online right away if necessary. If you're just backing up data, only you're home directory is necessary perhaps?

Some things to note:
- I've found that recent versions of tar seem to have a limit at about 27 Gigabytes in the archive.
- Using gzip and bzip make your backup less stable and prone to errors, but smaller. Only use this if you are keeping generations of backups.
- Haven't used cpio much to tell you anything about it.
- You can pipe tar and gzip through ssh so store your backup on another system remotely.
- I could go on and on! You have tremendous choice here!

There are whole books written on this subject! Hope this helps rather than confuses.
 
Old 11-09-2006, 12:59 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I would add one thing to my first post and to meetscott's comments. I prefer using split to break up a backup in to reasonable sizes. Then I use par2 to add redundancy to the backup. For example, when I knew I would be replacing the Distro version of my laptop, I backed up my HOME directory to an external USB drive. ( Note: It was FAT32 formatted so I needed to use split to break it up. I broke it up into around 300MB segments if I remember correctly. ) Instead of backing up the drive image, I backed up the files using tar with the gzip compression option, piping the output through split and using the /media/usbdrive/backup/ directory as a target. I was able to even do something like "cat /media/usbdrive/backups/homedirbu-Oct07.* | tar tzf -" to look at the contents of the backup. I also used par2 to create parity files to add some redundancy. The amount backed up was around 25GB.

Using Ghost or dd to backup and restore an image is useful if there is a dire emergency and you want to restore your original fresh setup to a new drive.
 
Old 11-09-2006, 02:18 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
If you're using Mandriva, then the backup tool in the control panel works great. Else I've heard that g4l (ghostForLinux) is good too. Before I used Mandriva's backup tool, I used to simply tar+gzip all the files I wanted to save.

Yves.
 
Old 11-09-2006, 03:27 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
This episode of the Linux Action Show has a section on backup solutions.
 
Old 11-16-2006, 01:16 PM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Just a reminder that '/' isn't the only separator allowed by sed's "s" command. In fact, the character after the 's' is automatically the separator for that substitution. This is especially useful if the text you're working on contains slashes. In fact, several friends & I use ',' as our "standard" separator, only reverting to '/' when there are commas to deal with.

BTW, this is also true in Perl.

I think one of the reasons Perl's detractors like to call it (among other things) a "write only language", is that so many regexes are so hard to read because of all the escaped slashes: e.g. "s/\/\//\/\/\//". (Quick, tell me what that one would do.) To my eye, such constructs look like a sparring match between Chuck Norris & David Carradine.

Now if there were only a way to change the wild card character when we deal w/ URL's. ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
backup for linux system in CF lbdgwgt Linux - Newbie 2 10-23-2006 06:10 AM
Hard Drive System Backup of Linux? KarlT Linux - Software 2 12-20-2003 08:03 PM
Help:ask for linux system backup solution! fredlong Linux - Software 4 12-01-2003 12:44 PM
Linux Raid system backup and restore ron4linux Red Hat 1 08-29-2003 12:57 PM
How to backup and restore a working Linux System redwolf Linux - General 3 07-27-2003 08:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration