Sei sulla pagina 1di 7

MyLinuxRamblings

Menu

How to Backup and Restore your Home directory


January 10, 2010 File System, Upgrading

9 Votes

If you dont keep your data separate from your operating system, i.e. on another
volume, then when you distro hop you need to be able to backup you Home folder
before you install your new OS. This is the problem Ive recently faced when moving
from XFCE based Xubuntu to CrunchBang.

If you have a second hard disk (internal or external) then this is relatively easy,
alternatively assuming you have space you cold use Gparted to create an additional
partition on your hard drive and use this, although as it is all on the same physical
disk it is more risky and therefore not my preference.

Whilst you can use rsync, TAR is the traditional way of backing up in Linux / Unix /
MAC OSX and ships as standard with all Linux distros.

For my purposes I have used the rather helpful instructions on Ubuntu forums
http://ubuntuforums.org/archive/index.php/t-93193.html provided by James
Fryman. Although dated, they still work. Ive distilled the forum post below

To Backup

In terminal type:

tar cf <name of archive>.tar.gz /home/<username>

In addition, when doing a tar backup, its also good to add the following flags : p &
(z/j)

-p will preserve the original file permissions

-z will compress using gzip (medium cpu usage, but less space)

-j will compress using bzip2 (lots of cpu, even less space)

-v verbose output (optional)

So, a full backup would look something like this:

tar c(z/j)vf <name of archive>.tar.gz /home/<username>

In place of the .gz file name extension you could also use bz2.

For more info on tar command parameters, from Terminal enterman tar.

To Extract (restore the backup)

In terminal type:
tar x(z/j)vf <name of archive>.tar.gz

In place of the .gz file name extension you could also use bz2.

A Real Example

To backup my home directory to a tar file located in the root of a second hard disk I
did the following:

a. Find out what disks and partitions exist:

sudo fdisk -l

This will display something similar to the screen-shot below

Change to the media directory

cd /media

b. Make a directory called disk1

sudo mkdir disk1

c. Mount my second hard disk (SDB1) to the disk1 directory

sudo mount /dev/sdb1 /media/disk

d. Change to the mounted disk

cd disk1

e. Enter the following to backup the home directory called myhomedirectory to a


TAR file called mybackup.tar.gz:

tar czvf mybackup.tar.gz /home/myhomedirectory

this creates a file called mybackup.tar.gz in the /media/disk1 directory which is a


backup of the home directory called myhomedirectory.

To restore, all I did under Crunchbang was to mount the second disk (as above) and
from my Home directory enter:

tar xzvf mybackup.tar.gz

This restores the contents of the tar file into the root of my home directory. It
includes the folder structure from root, but that is fine as it then allows me to copy
over what I need for my new distro. I can then delete what is not needed.
Furthermore, file permissions are maintained.

For more information on the tar file format go to


http://en.wikipedia.org/wiki/Tar_%28file_format%29

=-=-=-=-=
Powered by Bilbo Blogger

Share this:

Reddit Twitter Email Print Facebook 1

Loading...

Related

Using Clonezilla with FreeNAS or Network Share to Backup a Hard Disk

FreeNAS Network Attached Storage Server - Part 2: Configuration

Creating a MS-DOS Virtual PC under Virtualbox

Video File Encoding Format Information


Joining Files the Linux Way

4 thoughts on How to Backup and Restore your


Home directory

pete the plumber


February 10, 2015 at 02:46

Awesome source of info buddy. Love the time you spent.

Reply
Carl
March 3, 2015 at 12:42

Very good description. I too moved to #! and just run it on an external USB chip. Its
perfect.

In terms of backup, I use REDO (found here- http://redobackup.org/)

Its so easy to use and avoids the dread and complexities of using Clonezilla.

Reply

Pingback: Backup helpful tips | Polikin's Blog

Just me
November 18, 2017 at 13:36

Hey dude, thanks for this, you literally saved my home folder from my mistakes

Reply

Leave a Reply
Enter your comment here...

Blog Stats
558,161 hits

Follow Blog via Email


Enter your email address to follow this blog and receive notifications of new posts by email.
Join 66 other followers

Enter your email address

Follow

Recent Posts
Mini How To. Installing MINIDLNA in Ubuntu

Mini How To Install and Configure Samba on Ubuntu

How to Install VirtualBox Guest Editions in Ubuntu Server 14.04

Installing Madsonic 5.1 the FREE Subsonic alternative on NAS4Free

Install And Configure Nagios on Ubuntu 14.04 LTS

Installing Subsonic 5.0 on NAS4Free 9.2.x EmbeddedPART 2

Installing Subsonic 5.0 on NAS4Free 9.2.x EmbeddedPART 1

Installing MiniDLNA extension in NAS4Free

Mythbuntu 12.04LTS to 14.04.1LTS Upgrade

Dual Booting the HP Pavilion Sleekbook 15 with Windows 8.1 and Ubuntu 13.10

RSS
RSS - Posts

RSS - Comments

Most Popular
Posts | Pages | Comments

All | Today | This Week | This Month

How to Install VirtualBox Guest Editions in Ubuntu Server 14.04


5/5 (8 votes)

Mini How to Manipulate Images from within Dolphin in KDE4 without using an
external program!
5/5 (4 votes)

How to Configure the Conky System Monitor


5/5 (3 votes)

How to do a Frugal Puppy Linux 4.3.1 Install to a new Hard disk


5/5 (2 votes)

Installing Madsonic 5.1 the FREE Subsonic alternative on NAS4Free


5/5 (2 votes)

Archives
Select Month
Recent Comments
Just me on How to

Backup and Restore


your

John Fitzpatrick on
Mythbuntu 10.10
PART 3

VirtualBox | reboot
on Creating a MS-DOS

Virtual PC u

Roy Hill on How to


Configure the Conky

Sys

Clavius Walker on
Mini How To.

Installin

TUX Radar Linux


News
Stream It!
October 27, 2015

Linux Format 202 - Coding


Academy
September 2, 2015

Linux Format - 194 Next-gen


Linux
January 27, 2015

Linux Format 191 - Hack the Pi!


November 13, 2014

Linux Format 190 - Best Distro


2014
October 1, 2014

Utilities
Register

Log in

Entries RSS

Comments RSS

WordPress.com
Create a free website or blog at WordPress.com.

Potrebbero piacerti anche