Page 1 of 138 1231151101 ... LastLast
Results 1 to 10 of 1375

Thread: Howto: Backup and restore your system!

  1. #1
    Join Date
    Mar 2005
    Beans
    115

    Howto: Backup and restore your system!

    More recent up to date information this tutorial deals with can be found on the Ubuntu Wiki

    https://help.ubuntu.com/community/BackupYourSystem
    https://help.ubuntu.com/community/BackupYourSystem/TAR
    https://help.ubuntu.com/community/Ca...BackupRecovery


    Thread closed.


    Hi, and welcome to the Heliode guide to successful backing-up and restoring of a Linux system!

    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 xvpfz backup.tgz -C /
    Or if you used bz2;

    Code:
     tar xvpfj 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!

    2.1: GRUB restore
    Now, if you want to move your system to a new harddisk or if you did something nasty to your GRUB (like, say, install Windows), You'll also need to reinstall GRUB.
    There are several very good howto's on how to do that here on this forum, so i'm not going to reinvent the wheel. Instead, take a look here:

    http://www.ubuntuforums.org/showthre...t=grub+restore

    There are a couple of methods proposed. I personally recommend the second one, posted by remmelt, since that has always worked for me.


    Well that's it! I hope it was helpful!
    As always, any feedback is appreciated!
    Last edited by nothingspecial; August 30th, 2012 at 11:03 PM. Reason: Moved slash to end of command by popular vote
    "Windows is something to overcome"

    Howto's by me:
    Tweak firefox! (URL now works..)
    Backup/Restore your system!
    Avoid having to reboot


    Compentux.org
    , the Linux Tip & Howto gathering initiative!

  2. #2
    Join Date
    Apr 2005
    Beans
    63

    Re: Howto: Backup and restore your system!

    Excellent guide

    I'd like to try this, but I have very limited space on this hard drive (laptop) and I'm pretty certain I don't have room to generate the backup here. Is there a way to redirect the resulting backup.tgz to shared folder on my windows network instead of a local partition? Perhaps by using smbmount to mount the share, then create the backup.tgz from that location?

  3. #3
    Join Date
    Mar 2005
    Beans
    115

    Re: Howto: Backup and restore your system!

    Quote Originally Posted by Rehevkor
    Excellent guide

    I'd like to try this, but I have very limited space on this hard drive (laptop) and I'm pretty certain I don't have room to generate the backup here. Is there a way to redirect the resulting backup.tgz to shared folder on my windows network instead of a local partition? Perhaps by using smbmount to mount the share, then create the backup.tgz from that location?
    Exactly! Just make sure you exclude the mounted folder or you'll end up backupping your Windows drive as well!
    "Windows is something to overcome"

    Howto's by me:
    Tweak firefox! (URL now works..)
    Backup/Restore your system!
    Avoid having to reboot


    Compentux.org
    , the Linux Tip & Howto gathering initiative!

  4. #4
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Howto: Backup and restore your system!

    Quote Originally Posted by Heliode
    Exactly! Just make sure you exclude the mounted folder or you'll end up backupping your Windows drive as well!
    What about /dev and /sys folders ? They are virtual, so there is no need to archive them.

  5. #5
    Join Date
    Mar 2005
    Beans
    115

    Re: Howto: Backup and restore your system!

    O, right, guess that is why you can get errors at the end of the backup process. I guess it doesn't hurt to exclude them, but in my personal experiance it doesn't hurt to include them either!
    "Windows is something to overcome"

    Howto's by me:
    Tweak firefox! (URL now works..)
    Backup/Restore your system!
    Avoid having to reboot


    Compentux.org
    , the Linux Tip & Howto gathering initiative!

  6. #6
    Join Date
    May 2005
    Location
    Fremont, California, USA
    Beans
    330
    Distro
    Ubuntu 6.10 Edgy

    Re: Howto: Backup and restore your system!

    Quote Originally Posted by Heliode
    O, right, guess that is why you can get errors at the end of the backup process. I guess it doesn't hurt to exclude them, but in my personal experiance it doesn't hurt to include them either!
    Theoretically, yes it does.
    It'll backup /dev/hda which will end up giving you a how-ever-many gig image of your harddrive.... and if you're backing it up, why do you need that? You already have it.
    All it does is double the size of the bcakup file with a useless disk image that's only good for loopback mounting.
    - Kev
    Reg. Linux User #389145
    ThinkPad T42p running Breezy (with [Multi/Uni]verse, Marillat, Sarge, Cipherphunk and BMPx repos). All (sub)systems are a GO.
    Kill all the Spiders to save the Butterflies. Is this what we call Eden?
    Last.FM

  7. #7
    Join Date
    Jan 2005
    Beans
    Hidden!

    Re: Howto: Backup and restore your system!

    This is awesome. After I get my Thinkpad in and configured Ill use this to make a backup. Thanx.

  8. #8
    Join Date
    Mar 2005
    Beans
    115

    Re: Howto: Backup and restore your system!

    Quote Originally Posted by kvidell
    Theoretically, yes it does.
    It'll backup /dev/hda which will end up giving you a how-ever-many gig image of your harddrive.... and if you're backing it up, why do you need that? You already have it.
    All it does is double the size of the bcakup file with a useless disk image that's only good for loopback mounting.
    - Kev

    Ok I think you're right. I'll edit the howto.
    But if you just recreate the dev directory after restoring, does the system automatically recreate the device nodes?
    Somehow I don't think i've ever had the problem you discribe. My backups have always been somewhat proportional to the amount of data that was actually on the disk; I didn't have it suddenly double in size or anything. But if Linux just recreates the device nodes by itself then I guess it is save to exclude 'dev'.
    "Windows is something to overcome"

    Howto's by me:
    Tweak firefox! (URL now works..)
    Backup/Restore your system!
    Avoid having to reboot


    Compentux.org
    , the Linux Tip & Howto gathering initiative!

  9. #9
    Join Date
    Apr 2005
    Beans
    69

    Re: Howto: Backup and restore your system!

    Nice guide.

    But I used Norton Ghost which works perfectly for me. Norton Ghost 2003 supports EXT2/EXT3 filesystems. Older versions of Norton Ghost DON'T support EXT3 filesystems or Linux altogether.

    Please go to this site for a feature compare between the different Norton Ghosts versions: Norton Ghost compatibility with Linux.

    I ended up with a backup-image that's about 1 GB big, the amount of data on the disk that was backed-up by Norton Ghost was about 2 GB. So as you can see the compression was very good. I went from 2 GB to 1 GB.
    Last edited by maspro; May 18th, 2005 at 03:49 PM.

  10. #10
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Howto: Backup and restore your system!

    Quote Originally Posted by maspro
    Nice guide.

    But I used Norton Ghost which works perfectly for me. Norton Ghost 2003 supports EXT2/EXT3 filesystems. Older versions of Norton Ghost DON'T support EXT3 filesystems or Linux altogether.

    Please check go to this site for a feature compare between the different Norton Ghosts versions: Norton Ghost compatibility with Linux

    But it's a commercial application....

Page 1 of 138 1231151101 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •