Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old October 24th, 2005   #1
A-star
Gee! These Aren't Roasted!
 
Join Date: Feb 2005
Location: Heverlee, Belgium
Beans: 167
Ubuntu 6.06
Howto: Backup and restore your system!

This is a repost from a guide originally made by Heliode for backing up and restoring your system found here
I changed it so that it works in breezy (thanks to this thread where I found the solution).

Most of you have probably used Windows before you started using Ubuntu. During that time you might have needed to backup and restore your system. For Windows you would need proprietary software for which you would have to reboot your machine and boot into a special environment in which you could perform the backing-up/restoring (programs like Norton Ghost).
During that time you might have wondered why it wasn't possible to just add the whole c:\ to a big zip-file. This is impossible because in Windows, there are lots of files you can't copy or overwrite while they are being used, and therefore you needed specialized software to handle this.

Well, I'm here to tell you that those things, just like rebooting, are Windows CrazyThings (tm). There's no need to use programs like Ghost to create backups of your Ubuntu system (or any Linux system, for that matter). In fact; using Ghost might be a very bad idea if you are using anything but ext2. Ext3, the default Ubuntu partition, is seen by Ghost as a damaged ext2 partition and does a very good job at screwing up your data.

1: Backing-up

"What should I use to backup my system then?" might you ask. Easy; the same thing you use to backup/compress everything else; TAR. Unlike Windows, Linux doesn't restrict root access to anything, so you can just throw every single file on a partition in a TAR file!

To do this, become root with
Code:
sudo su
and go to the root of your filesystem (we use this in our example, but you can go anywhere you want your backup to end up, including remote or removable drives.)
Code:
cd /
Now, below is the full command I would use to make a backup of my system:
Code:
tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /
Now, lets explain this a little bit.
The 'tar' part is, obviously, the program we're going to use.

'cvpfz' are the options we give to tar, like 'create archive' (obviously),
'preserve permissions'(to keep the same permissions on everything the same), and 'gzip' to keep the size down.

Next, the name the archive is going to get. backup.tgz in our example.

Next comes the root of the directory we want to backup. Since we want to backup everything; /

Now come the directories we want to exclude. We don't want to backup everything since some dirs aren't very useful to include. Also make sure you don't include the file itself, or else you'll get weird results.
You might also not want to include the /mnt folder if you have other partitions mounted there or you'll end up backing those up too. Also make sure you don't have anything mounted in /media (i.e. don't have any cd's or removable media mounted). Either that or exclude /media.

EDIT : kvidell suggests below we also exclude the /dev directory. I have other evidence that says it is very unwise to do so though.

Well, if the command agrees with you, hit enter (or return, whatever) and sit back&relax. This might take a while.

Afterwards you'll have a file called backup.tgz in the root of your filessytem, which is probably pretty large. Now you can burn it to DVD or move it to another machine, whatever you like!

EDIT2:
At the end of the process you might get a message along the lines of 'tar: Error exit delayed from previous errors' or something, but in most cases you can just ignore that.

Alternatively, you can use Bzip2 to compress your backup. This means higher compression but lower speed. If compression is important to you, just substitute the 'z' in the command with 'j', and give the backup the right extension.
That would make the command look like this:
Code:
tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /
2: Restoring

Warning: Please, for goodness sake, be careful here. If you don't understand what you are doing here you might end up overwriting stuff that is important to you, so please take care!

Well, we'll just continue with our example from the previous chapter; the file backup.tgz in the root of the partition.

Once again, make sure you are root and that you and the backup file are in the root of the filesystem.

One of the beautiful things of Linux is that This'll work even on a running system; no need to screw around with boot-cd's or anything. Of course, if you've rendered your system unbootable you might have no choice but to use a live-cd, but the results are the same. You can even remove every single file of a Linux system while it is running with one command. I'm not giving you that command though!

Well, back on-topic.
This is the command that I would use:
Code:
tar xvpzf backup.tgz -C /
Or if you used bz2;
Code:
tar xvpjf backup.tar.bz2 -C /
WARNING: this will overwrite every single file on your partition with the one in the archive!

Just hit enter/return/your brother/whatever and watch the fireworks. Again, this might take a while. When it is done, you have a fully restored Ubuntu system! Just make sure that, before you do anything else, you re-create the directories you excluded:
Code:
mkdir proc
mkdir lost+found
mkdir mnt
mkdir sys
etc...
And when you reboot, everything should be the way it was when you made the backup!

Last edited by A-star; June 12th, 2006 at 02:19 AM..
A-star is offline   Reply With Quote
Old October 24th, 2005   #2
bionnaki
Dark Roasted Ubuntu
 
Join Date: Aug 2005
Beans: 1,028
Re: Howto: Backup and restore your system!

thanks!
bionnaki is offline   Reply With Quote
Old October 24th, 2005   #3
bionnaki
Dark Roasted Ubuntu
 
Join Date: Aug 2005
Beans: 1,028
Re: Howto: Backup and restore your system!

I just realized an entire system backup from / would be about 26 gigs. I'd like to have everything on DVD-R, so what do you think would be the best way to divide the backup? thanks again!
bionnaki is offline   Reply With Quote
Old October 24th, 2005   #4
BLTicklemonster
Tall Cafè Ubuntu
 
BLTicklemonster's Avatar
 
Join Date: Oct 2005
Location: Rome, Ga
Beans: 2,611
Ubuntu 8.10 Intrepid Ibex
Send a message via MSN to BLTicklemonster Send a message via Yahoo to BLTicklemonster
Re: Howto: Backup and restore your system!

Quote:
Originally Posted by bionnaki
I just realized an entire system backup from / would be about 26 gigs. I'd like to have everything on DVD-R, so what do you think would be the best way to divide the backup? thanks again!
"
__________________
Al Gore didn't invent the Internet, but he did make up global warming.

-David Rockefeller, March 08, 2009
BLTicklemonster is offline   Reply With Quote
Old October 24th, 2005   #5
matthew
Bubbleheaded Star Child
 
matthew's Avatar
 
Join Date: Apr 2005
Location: Parts Unknown
Beans: 8,771
Ubuntu 9.04 Jaunty Jackalope
Re: Howto: Backup and restore your system!

Quote:
Originally Posted by bionnaki
I just realized an entire system backup from / would be about 26 gigs. I'd like to have everything on DVD-R, so what do you think would be the best way to divide the backup? thanks again!
One thing I do is backup a lot of my data separately. I have my mp3's (almost 10GB worth) in a directory called /music which I backup separately from /videos which is separate from /files-text which is separate from /files-spreadsheet and so on. It would take a little longer to do the backup and restore, but then you can put just one file type on a DVD (or multiple dvd's...just do A-L in one and M-Z on another and so on).

Then I do a system backup excluding all those data files/directories.
__________________
Forum FAQ | Forum CoC | what's a troll? | are you imposing?
my blog | my writing

Don't ask support questions in PMs--post a thread so everyone can benefit!


matthew is offline   Reply With Quote
Old October 24th, 2005   #6
bionnaki
Dark Roasted Ubuntu
 
Join Date: Aug 2005
Beans: 1,028
Re: Howto: Backup and restore your system!

yeah, I guess that makes sense. thanks man
bionnaki is offline   Reply With Quote
Old December 5th, 2005   #7
Joeak
5 Cups of Ubuntu
 
Joeak's Avatar
 
Join Date: Nov 2005
Location: Anchorage
Beans: 35
Ubuntu 6.10 Edgy
Re: Howto: Backup and restore your system!

(shameless copy from the net. modify tar to include split below)

Not tar per se, but you might be able to do this with 'split'. You'll
have to reassemble the pieces afterwards:

tar czvf - source | split -b 650m tarpiece-

...should create files tarpiece-aa tarpiece-ab tarpiece-ac...

To reassemble, copy to disk, then:

cat tarpiece-* > file.tar.gz

...will reassemble the tarfile.
Joeak is offline   Reply With Quote
Old October 25th, 2005   #8
zigford
5 Cups of Ubuntu
 
zigford's Avatar
 
Join Date: Jul 2005
Location: Sunny Coast Australia
Beans: 30
Hardy Heron (Ubuntu Development)
Send a message via ICQ to zigford Send a message via MSN to zigford Send a message via Skype™ to zigford
Re: Howto: Backup and restore your system!

Quote:
Originally Posted by bionnaki
I just realized an entire system backup from / would be about 26 gigs. I'd like to have everything on DVD-R, so what do you think would be the best way to divide the backup? thanks again!
If you want a better backup system, check this thread out:
http://www.ubuntuforums.org/showthread.php?t=80790

It is a script I wrote that helps you cut out the things you don't want to backup. You can set it to automatically exclude files from your backup the exceed a specified amount.
zigford is offline   Reply With Quote
Old October 26th, 2005   #9
_Pete_
5 Cups of Ubuntu
 
Join Date: May 2005
Location: Jyväskylä, Finland
Beans: 24
Xubuntu 9.04 Jaunty Jackalope
Send a message via MSN to _Pete_ Send a message via Skype™ to _Pete_
Re: Howto: Backup and restore your system!

Quote:
Originally Posted by bionnaki
I just realized an entire system backup from / would be about 26 gigs. I'd like to have everything on DVD-R, so what do you think would be the best way to divide the backup? thanks again!
There's a utility called split which you can use to split files to specified size.
_Pete_ is offline   Reply With Quote
Old October 26th, 2005   #10
DDM
Just Give Me the Beans!
 
Join Date: Apr 2005
Beans: 50
Re: Howto: Backup and restore your system!

My tips for backing up:

It's easiest to have your media (movies, music) in a separate partition. Mine is in a FAT32 partition just in case I have to venture into Windoze for a few mins.
I have had problems with the method described here, especially when switching filesystems. Now I use Knoppix DVD with partimage. Very easy stuff, never proven me wrong.

And when choosing bz2 vs gzip compression, in my experience bz2 takes about 3 times as long as gzip, and only gives an extra 5-10% when compressing my ubuntu partition. But then again, if you have the extra time, then go for it.
DDM is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

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

Forum Jump


All times are GMT -4. The time now is 08:26 AM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry