copying a home directory onto a removable drive and back

Patrick Doyle wpdster at gmail.com
Wed Jul 28 15:24:52 UTC 2010


On Wed, Jul 28, 2010 at 9:15 AM, Adam Funk <a24061 at ducksburg.com> wrote:
> I want to copy my home directory onto a USB drive (formatted to ext3),
> shuffle the partitions around on the computer, and copy my home
> directory back (onto a new, blank partition).  I can think of four
> ways to do it, although I'm not familiar with using the fourth:
>
> cp -r
> rsync
> tar
> cpio
>
> Recommendations?
>
Over 20 years ago, I learned the following magic incantations and they
have served me well (although they have changed very slightly over 20
years).

I'll start simple

$ tar -cjf /path/to/backup/file.tar.bz2 .
-- create (-c) a TAR archive, compress it with bzip2 (-j) and store it
in a file (-f /path/to/blah/blah/blah) instead of on a tape drive, of
the current directory (".").  All files, device nodes, hard links, and
symbolic links will be archived.

$ tar -xjf /path/to/backup/file.tar.bz2
-- extract (-x) files from a TAR archive that was compressed with
bzip2 (-j) and stored in a file (-f /blah/blah/blah) instead of on a
tape.  Without any other arguments, all of the files in the archive
will be extracted into the current directory.

You could use this (as I have done in the past) to archive your home
directory into a tarball on the USB stick (formatted however you would
like -- although there might be some complications if you cross a 2GB
file size) and to restore everything into an empty pristine new home
directory.  Note that you will have to be root when restoring, if you
want the file ownerships to match, otherwise everything will be owned
by you (which may be what you want).

If you specify a filename of - (dash) then the archive is written to
stdout instead of a file.  You can combine this with ssh to do
something like:

(cd srcdir; tar cjf - .) | ssh someothermachine "(cd destdir; tar xjf -)"

but that gets a little esoteric.

Have fun!

--wpd




More information about the ubuntu-users mailing list