In a nutshell
Backing up and restoring is very simple in Ubuntu, at least for me, the way I like to do it.Back up Basically, all you need to do is copy everything out of your /home/username directory, making sure you include all those hidden files. With the home/username folder open, look in the 'View' menu, and click 'Show Hidden Files'. The hidden files are the ones with a . in front of the file name. Remember to export your Firefox bookmarks if you can, I'll explain how to do that further down the page. If you will be restoring to the same version of Ubuntu, you might also want your software packages from /var/cache/apt/archives. If you have any configuration files you want to save like specially modified /etc/apt/sources.list which gets updates from your own ISP's FreeZone mirror site, you might want to include that too. You should make regular backups to some other media such as a different hard disk or USB drive, or to a DVD or CD-ROM. Restore All you need to do is copy the files you want into your new /home/username folder. It's pretty simple really. The files you copy into your new installation include your regular documents, music, pictures and so on. After that there may be a few apps that you may use which have their settings stored in hidden files (with a . before the filename). These apps vary from user to user, according to what programs different people use. For me the .gpass folder is important, because that contains all my passwords for Password Manager. After that there is evolution email, addressbook, calendar, memos and tasks, which are explained in this web page, and Firefox bookmarks. Firefox likes us to use it's 'import' and 'export' features, and evolution tasks might be starting to get that way too. Finally, if you have software packages to restore you will need to use sudo commands to restore your collection of .deb files to /var/cache/apt/archives and special customized /etc/apt/sources.list. There could be a few things I missed, but those are the main ones for me. I imagine everyone will be different, but that should give most people a few ideas to get started with. |
| Small Scale Back- ups and Restoring MBR backup and restore. - for paranoid Windows users mainly The cp command. - how to back up and restore individual files Normal Backup and Restore Drag and Drop method of backing up. Drag and Drop Restoring. - for normal files Evolution Restoring (drag and drop method) Firefox Bookmarks (Firefox Method) File Compression - create or extract an archive Using the Terminal Evolution Back-ups, Terminal commands method. Evolution Restoring, with Terminal commands Make a backup script to run your backup commands automatically Configure 'crontab' to run your backup script regularly at the times you set Make a restore script Back-up and Restore Added Software tar -nothing here yet - to be added rsync -nothing here yet - to be added Whole Partition Back-up and Restore Complete Back-up Using File Compression GParted Partition Back-up. dd command - partition Entire Hard Disk dd command - entire hard disc Security Reminder Backup Security |
| TIP: backup naming convention I think it's a good idea to name backup files by beginning with a number representing the date, but backwards. The first two digits represent the year, the next two represent the month and the last two digits are for the day the backup was made. After the date, I type a regular name describing what the file is. For example, '080525MBR.img' would mean a MBR image made on the 25th of May in 2008. The reason I like to type the date in backwards is just so they'll appear in chronological sequence in whatever directory I store them in. I find that very convenient. |
| MBR Backup and Restore If you want to, you can make a back up of your hard disk's MBR with a Linux Live CD such as a ubuntu 'desktop' Live/Install CD before you begin your Linux installation. This backup is for easily restoring your old boot loader if you make a mistake during the installation. This MBR backup may be useful to Windows users because it will include your MBR's 'disk signature', which is important for booting Windows 7 and Windows Vista. No Linux installation will overwrite the 'disk signature' in your MBR, but if you use a partition editor to set a new disk label, (format your hard disk), then your MBR will have a new 'disk signature'. You can copy the MBR backup file to any media you like for storage. In this example I used a USB disk. You may use a floppy disk or a CD-ROM just as easily. Create the MBR backup with a dd command
Where: your hard disk is seen as 'sda', by Linux, feel free to replace the 'a' with a 'b' or 'c' and so on if it's the second or third hard or more hard disk's MBR you're copying. Where: '080525MBR.img' will be your name for your MBR backup file, you can make up your own file name here, anything you like. quote:
Copy the MBR backup to USB disk:
Restore command:
Where: your hard disk is seen as 'sda', by Linux, feel free to replace the 's' with an 'h' if appropriate, or maybe the 'a' with a 'b' or 'c' and so on if it's the second or third hard or more hard disk's MBR you're copying. Where: 080525MBR.img is the name of your MBR backup file. Here's a link to a website with more dd commands, Learn the DD command - LinuxQuestions.org |
| The cp Command Every time we need to edit some important configuration file in Ubuntu we always make sure there is a back-up copy of the file first. Any good how-to that you may be using will always ask you to use the cp command to make a backup or your original configuration file(s) before you modify the file(s). No-one seems to bother to explain to newcomers what they need to do to actually restore the file if they need to. Lets try this out on a regular file just to see how it works, okay? Now say I am working on a text file called '2009_diary'. Make one yourself in your own computer and try this. Type a few lines of text into it for testing purposes if you like. I made a back-up of the file by typing this code in 'terminal' (if '2009_diary' is a file located in my /home/herman directory). code:
The same thing should work for you too, try it. Later, I make a lot of alterations to a story in my '2009_diary' file, but then I decide they are no good and I want to go back to my original way of telling the story. To restore my '2009_diary', I can simply open up a 'terminal' again, and type in pretty much the opposite command of the one I typed when I made the back-up of the file, code:
Test this out yourself with your own '2009_diary' file, alter the text and then restore the original back-up copy and check to see what happens. It's actually a pretty nifty little trick. Linux is wonderful!
The same commands are used for backing up and restoring real configuration files, but you probably need to insert the word 'sudo' before the commands. For example, you might have read the 'GRUB page' of this website, and made a back-up of GRUB's menu.lst file before editing it. The command used for that was: code:
Now if we are not happy with the alterations we made to the /boot/grub/menu/lst file, we can easily restore the old one by typing the following code into our terminals: code:
...and that is how to perform small scale back-ups and restore jobs in Ubuntu. There is one possible (major) problem to be aware of when you are new to this. Imagine you followed one how-to and back up some text file like grub's menu.lst, and then you modify it. Later, you follow another how-to and make a new back-up and then make more modifications to the same file. The second back-up will overwrite your first back-up so you will lose the original copy of that file. Then if you later regret something you did when you edited the file the first time you might not be able to get your computer back to its original state easily. Every user should think about this and decide what rules they want to make for themselves in regards to this type of situation. Maybe you should get in the habit of making an extra copy of the backup file and store it out of the way somewhere like in a special 'Backups' directory you might make for yourself. Alternatively, you might make it a rule that you only make a back-up copy of the original file once, and from then on always check for the presence of a back-up file before editing the file. For example, use the 'ls' command to have a look around and see what's there first. code:
If there is already a menu.lst_backup in existence we may not want to make a new backup and overwrite the original backup. In those circumstances we might just want to skip that step in the how-to we are following. |
|
Normal Back- up and Restore
Drag and Drop Method for making backups
Drag and Drop Method for restoring (General data) When it's time to restore, just find what you want in your storage media and copy it back to your home (username) folder where it came from.
Firefox Bookmarks (Firefox Method) Sometimes we get too many bookmarks and we want to start again fresh and organize things a different way, but we don't want to lose some of or favorite bookmarks. Export Bookmarks File Start your firefox web browser. Click 'Bookmarks', then 'Manage Bookmarks', then on the 'File Menu' of the 'Bookmarks Manager' window, click 'export'. That will start the 'export wizard'. Give your file a name that means something to you, or the day's date. Choose a folder to save it in such as /home/username/Backups, and click 'Save'. Import Bookmarks File Have the bookmarks file of your choice copied out of your backups folder or wherever you kept it and pasted out in the open in your /home/username folder ready to be imported. Start your firefox web browser. Click 'Bookmarks', then 'Manage Bookmarks', then on the 'File Menu' of the 'Bookmarks Manager' window, click 'import'. That will start the 'import wizard'. Click 'next;, and navigate to your '/home/username/Backups' folder. Find your bookmarks file to be imported and click 'Open'. I noticed that when I did this I ended up duplicating some of the bookmarks I already had rather than replacing them. That was annoying. Groups of sub folders can be deleted from the right-hand pane in 'manage bookmarks' by highlighting one and holding down the 'shift key' and clicking a lower one in a group. Then right-click on the red highlighted rectangle including all folders to be deleted and click 'delete'. You can empty your bookmarks right out completely this way if you want, ready to start a brand new collection , or import a different file.. Evolution Restore(GUI navigation method) Some people get too much mail, and it begins to take up a lot of room in their hard disk. All you need to do is copy your .evolution addressbook, calendar, mail, memos, and tasks to your Backups directory for temporary storage. It's a good idea to put it in a folder with the date as part of the file name, such as ' 090626.evolution.bak' or something like that. When you're ready, you can copy it from there to a more permanent backup, such as to another media like a USB external hard disk or a CD or DVD-ROM. To restore, simply navigate to your .evolution directory again, copy and paste them in there, overwriting your new directories of the same name. (Presuming of course, there's nothing in the ones you're about to overwrite that you'd like to save first). It's best to make sure Evolution is not running while you restore it or it will probably crash, so just close evolution before you start restoring it. Usually, your e-mail will show up right away, when you go and start evolution up on your icon for it on your top panel. Your addresses, calendar appointments and tasks might not show up until after your re-start your computer. File Compression To compress a file in Ubuntu, you only need to right-click on it and click 'Create Archive', and then choose a type of file compression. To extract files from an archive, we just right-click on it and click 'extract here'. Compressed files take up less storage space and they are easier to transfer around. If you need to send them over a network they're more likely to arrive intact. The only downside is, it takes time to compress and extract files, especially large files.
links: File Compression - Quick explanation, and File Compression Tools For Linux - Another explanation with just a few more details.
|
Make a backup script Make your list of backup commands run automatically by making a backup script! A script is a text file that has been given a name that ends with the extension .sh (short for 'shell', since they're really supposed to be called 'shell scripts', most most people just call them scripts. A shell script contains a list of commands. They are the same as the commands you would type in a terminal normally, but this way you can run a whole list of commands in one hit. If you type: introduction to shell scripting (or something like that) into google you will have pages and pages of helpful tutorials. My favorite one is from Rute User's Tutorial and Exposition, and the exact chapter is: 7. Shell Scripting If you want to really learn shell scripting, it would be best to refer to a proper tutorial like Rute's where everything is explained a lot better than in this page. 1. Make a directory in your /home/username folder and call it: Backups you could also call it any other name you like. One requirement for shell script is shell scripts need to have #!/bin/sh at the top. Another requirement is it has to be given file permissions that mark it as being executable. 2. Create a new empty file in the Backups directory called: evo_bak.sh (or something similar).
4. type in the following commands: for example,
5. Take a look at the file permissions of the new evo_bak.sh file with: ls -l all_backups
For the script to work it must have permission to be executed. We can fix that with a chmod command,
We can test our script to make sure it works by typing the path and name of the script in out terminal, like this,
Inside that will be a backup of our evolution addressbook, calendar, mail and tasks folders. If you want to keep (preserve) this particular backup, you must rename it. I suggest renaming it something like: 070414.evo.bak (or something like that), it's a good idea to include the date in it. I'm just deleting mine for now, because in a few minutes I'll be making a new one to test the crontab command to make sure it works, so I'll be making another backup then too. |
Use 'crontab' Make your automatic backups happen automatically with crontab. Program your computer to make regular backups at set times with crontab. As soon as you learn how to use crontab, you'll be able to use crontab to make your computer do lots of other handy things for you as well. The Official Ubuntu Wiki has a good page on cron, if you want to learn to use crontab you should read that as well, CronHowto. The crontab command has three options,
To see if the cron daemon is already running,
crontab -r - the -r option causes the current crontab to be removed! This will remove (i.e. delete) your current crontab. "Don't try this at home, folks", this is just a demonstration, you should be careful not to remove anything that might be important.
crontab -e The crontab -e command opens a file in /var/spool/cron/crontabs with the text editor Nano. Nano is the default command line text editor for Ubuntu. See this website's Getting Started with GNU nano Text Editor. The files in /var/spool/cron/crontabs should only be edited via the crontab command. When you exit the editor, the new crontab file will be installed automatically. Code:
You will see a file open in your text editor, usually nano by default, (mine's nano anyway), and the empty file has a commented line like this (below).
You will want to type in a line of commands in the correct format in order to set up your cron job. 'm' column is for minutes, you can type any number here from 0 to 59, an * means every minute. 'h' column is for hours, you can type any number here from 0 to 23, or * for 'every'. 'dom' column is for 'day of the month' from 1 to 31, or * for 'every'. 'mon' column is for 'month of the year'use a number 1 to 12 or type 'march', or * for 'any'. 'dow' column is for 'day of the week', mon=1, tues=2, wed=3, thu=4, fri=5, sat=6, sun=7 Note: with this method there is no column for 'user' because the file itself is already user-specific.
Use crontab -l to check and make sure the cron daemon really running,
Now all you need to do is keep an eye out for your new daily evolution backup to appear in your /home/username/Backups directory. It will be automatically updated every day at the same time as long as you leave the cronjob running. Email can occupy large amounts of hard disk space. Keeping a back up of all your email all the time like this doubles the amount of disk space used for your email. If you are short of disk space you may need to disable this cron job temporarily. # Placing a hash mark in front of the line in crontab will disable the operation if you want to stop it for a while. If you want to save a backup from any particular day, just rename the folder. You can name it anything you like, but I suggest making up a name that includes the date of the backup in it. For example: 070428evolution.bak The main purpose of this is to make it quick and simple to copy these backups to a CD-ROM once in a while. You should copy them to a CD every once in a while. Then as soon as you are sure you have them safely copied to CD-ROM, delete them to recover your hard disk space. |
Make a restore script
You can restore everything
separately with a series of commands or you can make a matching restore
script, let's call it: evo_rest.sh
Apply the chmod command again to enable the new shell script to be executed and check with ls -l that the file permissions are right.
Or, try right-clicking on the script and click 'Open', then 'Run in Terminal'. The script will instantly overwrite your evolution files with whatever is in the backup. If you want to restore to an earlier date, copy your present daily_evobkup folder and rename it with today's date in the name to preserve your current files. Then just find a folder with the date you need in your all_backups folder and rename that folder: daily_evobkup ...that will overwrite your current daily_evobkup folder and all its files. Then run the restore script. That will restore your evolution to an earlier time. |
| How to Back-up and Restore Added Software Just go to /var/cache/apt/archives and copy all the packages you want before you delete your old operating system and record the packages to some media or another partition. Then when you have a new operating system and you're ready to install your old software, just copy the packages into your /home folder and use the dpkg -i command. To test this out with a simple example I copied the package for MacSlow's Cairo-Clock from one operating system's /var/cache/apt/archives to the /home/herman directory in a newer install,
This was just a simple program, I haven't gotten around to trying to see what is the most I can get away with yet. I imagine very often there will be programs with dependencies. Another thing that might be interesting to try would be leaving a lot of packages on a CD-ROM and seeing if Add/Remove programs will take it from the CD when deb cdrom is enabled in /etc/apt/sources.list. I know that APTonCD works something like that. I haven't tried that out yet either though. Links: Backup installed packages on ubuntu - ubuntugeek Create backup of all installed packages using APTonCD in Ubuntu - ubuntugeek about apt-get by ubuntu_demon --> A Concise apt-get / dpkg primer for new Debian users. |
| Here's another way to do it, When you have an installed operating system with all of your favorite software added, you might want a list of the programs you installed so you can easily install the same ones again in case you ever need to re-install for some reason. This is only good for installing in the same version, not for upgrading to a newer version of Ubuntu. Installed .deb packages are stored in /var/cache/apt/archives, and you can make a backup of all the packages in /var/cache/apt/archives and copy it into another /var/cache/apt/archives in another installation of the same version of Ubuntu so you won't have to re-download the same packages again from the internet.
This command will output a list of all packages installed by default in a new installation to a text file and call it installedI.txt.
This command will output another list of all installed packages to a text file and call it installedII.txt.
Then,
|
|
Whole Partition Back-up and Restore
Sometimes we want to make a backup of an entire operating system, complete with added software and settings. Copy and Paste the whole partition with GParted This was the original method I had here, I'll still keep it here for a while in case it's useful to anyone. This was my favorite method for a long time. Backing up with GParted It's easy to resize your Ubuntu operating system to as small as possible and just copy and paste the whole thing to an area of spare disk space. That will be a fast and easy way to back up everything, including added software and system settings, the whole lot. It only takes me about ten minutes to copy and ten minutes to restore. Most people would want to remove some of their stored data first in order to shrink the partition to a very small size. Restoring with GParted You just copy the back-up copy of the partition you made earlier and paste it. Then you re-size it to the size you want again. Be sure to delete the old partition first, though, to make sure you get the same partition numbers as you had before. If you get different partition numbers you will need to re-install GRUB. Complete Back-up Using File Compression Sometimes, using file compression to make one big tar file is the best thing to do. You can get a lot of work done a faster that way sometimes, and squeeze more onto your back-up media too. Here's a link to a way to make a more complete back-up and restore job, using file compression. Partimage Partition Back-up It would be best to look at aysiu's tutorial, Use PartImage NOTE: Use your spacebar on your keyboard to move the cursor in Partimage. GParted LiveCD and Parted Magic both have Partimage in them. To start Partimage in GParted LiveCD just open a terminal and type: partimage Following are more links, Partimage Home Page, http://www.partimage.org/Main_Page Partimage Manual, http://www.partimage.org/Partimage-manual_Usage GParted LiveCD also has Clonezilla added to it by LarryT as well. Partimage is safer for most people to use than the dd command. dd command Here is a link, Howto: Backup and restore your system! - Heliode - Ubuntu Web Forums. Another way to do things is to copy an entire partition to a file in another hard disk. Possibly the partition can contain an entire working operating system. backup
restore
Where: 'OCZ_SAVER' is the name of the mount point for the file system you want to store your backup in. Where: 'ocz.image' will be the file name for the backup image. Note: It's wise to reduce the size of your partition using a partition editor like GParted before making your backup with the dd command. You may even wish to copy files out and store them elsewhere. The reason this is a good idea is because the dd command copies everything exactly and perfectly the way it is, including empty space in your file system. It's not only a waste of disk space to be backing up empty space, but also we can run into problems restoring. We can use the dd command to copy to an equal or larger disk area but we can't copy a large partition to a smaller one. That means it's possible to get ourselves into a situation where we can't restore. Notes:
Note: Windows 7 and Vista users, you should consider also making a backup of your original hard disk's MBR. See MBR backup and restore. Also, check your EULA. CAUTION: Be very careful with the 'dd' command, if you accidentally run it backwards and copy the damaged operating system to the good one you will destroy your good copy of the operating system! Please double check and then check again before running the command. |
|
Entire Hard Disk
Clonezilla - Clonezilla is safer for most people to use than the dd command. Link: Clonezilla Imaging By Raymond Siudak.pdf dd command Copy an entire hard disk to another hard disk,
This command is useful when you want to replace a hard disk with a larger one, or if a hard disk is on it's way out but still readable, and you want to copy the contents to a new hard disk in time before the old one deteriorates too much further. You would need to issue this command from a Linux operating system running in another media, such as a Live CD or USB operating system, or an operating system installed in another different hard disk. CAUTION: Be very careful with the 'dd' command, if you accidentally run it backwards and copy the blank disc to the one with the data you will erase all your data! Please double check and then check again before running the command. |
Security Reminder It's always recommended to keep making regular backups to some other media than the hard disk your operating system is running in. Naturally, if you store your backups anywhere where others can get ahold of them, you potentially have a huge security loophole. In case you haven't thought of it already, if could be a good idea to keep your backup media in a locked box of some kind or even in a safe if the backups might contain any kind of sensitive data. Maybe consider burying them in your back yard or something. (If the data isn't too hypersensitive). They'll be safe from fire and most natural disasters under some soil and you'll be able to dig them back up again some day. Some people deliberately destroy old backups after a certain length of time too. If you make encrypted backups, you will risk losing your data in the long run since the same software you used to encrypt the file may not still exist to decrypt the file again someday. You will also still need to keep the keys or password somewhere safe. An encrypted backup is worse than useless if you lost the key or forgot the password. Whatever you decide to do, just make sure you remember to think about security. |