forums.xandros.com Forum Index forums.xandros.com
Xandros User Forums
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Creating Backups & Copying with TAR (Tutorial)

 
Post new topic   Reply to topic    forums.xandros.com Forum Index -> Tips & Tricks
View previous topic :: View next topic  
Author Message
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Fri Apr 08, 2005 12:12 pm    Post subject: Creating Backups & Copying with TAR (Tutorial) Reply with quote

Why use TAR? A GUI may not always be there when doing the really BIG jobs. TAR is a tested and true industrial stenght file archiver; where any other archiver would quit TAR will keep on going; TAR has been extensively used in both Linux & *BSD for years. TAR has 2 popular compression formats BZIP2 & GZIP which I will use in examples; BZIP2 compresses the archives smaller than GZIP; however, BZIP2 will take longer to compress than GZIP.

Understanding how to use TAR will have greater implications & uses like backing-up your partitions; copying your data to different partitions/drives of different sizes; and converting your partitionīs filesystem like EXT3 to a different format like Reiserfs.

To create a BZIP2 archive with TAR:

# tar -cpvjf /destination/filename.tar.bz2 /source

To restore a BZIP2 archive with TAR:

# cd /
# tar -xpvjf /source/filename.tar.bz2

To create a GZIP archive with TAR:

# tar -cpvzf /destination/filename.tar.gz /source

To restore a GZIP archive with TAR:

# cd /
# tar -xpvzf /source/filename.tar.gz

Copying with TAR:

# cd /source
# tar lcf - .|(cd /destination; tar xpvf - )

Explanation of TAR flags:

c - copy
x - extract
v - verbose (basicly shows what files are being copied at the time)
j - BZIP2 compression
z - GZIP compression
f - destination/source of archive name & what path is getting copied/restored
p - copies the file permissions as well
l - stays in the local filesystem when copying
There are more flags simply type:
# tar --help
to find out what these do.

Tutorial:

Ok; so lets start a console window in Xandros as root user.
Weīre going to backup our /home directory data using TAR;

# tar -cpvzf /root/homedata.tar.gz /home

You can then copy /root/homedata.tar.gz to another medium to keep it as a backup.
Now lets do a test restore:

# mkdir /root/test (makes a folder called test in /root)
# cd /
# tar -xpvzf /root/homedata.tar.gz

You can now start Xandros File Manager as Root and examine the contents of /root/test and you will notice itīs an exact copy /home; you can now delete the folder called test in /root.

Now we are going to go back to the console as root and copy files using TAR;

# mkdir /root/test (makes a folder called test in /root)
# cd /home (changes current folder to /home)
# tar lcf - .|(cd /root/test; tar xpvf - )

You can now start Xandros File Manager as Root and examine the contents of /root/test and you will notice itīs an exact copy /home; you can now delete the folder called test in /root.


Gain some confidence using the TAR command in Xandros and then we can later cover more using TAR on a Linux rescue CD. Wink
_________________
Linux simply works for me...
Registered Linux User 384461


Last edited by aldube on Tue Nov 29, 2005 5:15 pm; edited 12 times in total
Back to top
View user's profile Send private message
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Fri Apr 08, 2005 12:40 pm    Post subject: Reply with quote

My PartImage Rescue CD Tutorial will prepare you for the next step in using TAR. Wink

How to use the PartImage Rescue CD. (Tutorial)
http://forums.xandros.com/viewtopic.php?t=14123
_________________
Linux simply works for me...
Registered Linux User 384461
Back to top
View user's profile Send private message
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Fri Apr 08, 2005 1:47 pm    Post subject: Reply with quote

So now you have learned to use TAR and the PartImage Rescue CD.

PartImage has an advantage over TAR in that PartImage can create multiple 700MB file segments making it possible to copy these to CD.

TAR has some advantages over PartImage in that:
1 - TAR can enable you to copy your partition data to another partition/harddrive of a different size.
2 - TAR can enable you to copy your partition data to another filesystem without having to start from srcatch.
3 - TAR can copy just the folders you want rather than the whole partition.

The starting point of the following Tutorial will be the command prompt after booting the PartImage Rescue CD.

Tutorial:
The assumption here is /dev/hda1 is your Windows partition (fat32) and /dev/hda2 is your Xandros partion.

To backup:

# mkdir /a
# mkdir /c
# mount /dev/hda1 /a
# mount /dev/hda2 /c
# tar -cpvjf /a/xandros3.tar.bz2 /c

**Warning**
Donīt do following example unless plan on changing your filesystem.
If the Xandros filesystem was EXT3 and you wanted to change it to Reiserfs you could do the following after a PartImage Rescue CD reboot:

# mkdir /a
# mkdir /c
# mount /dev/hda1 /a
# mkfs -t reiserfs -f /dev/hda2 (even if not changing filesystem type this will format your partition.)
# mount /dev/hda2 /c
# cd /
# tar -xpvjf /a/xandros2.tar.bz2
# cd /a/etc
# mc
Find and select fstab Press F4 key to edit fstab change EXT3 under /dev/hda2 / to reiserfs & that defaults 0 0 follows it; press F2 to save and F10 twice to exit mc.
Then reboot on you Xandros 3 CD and press Shift key when the option comes up and then select the Restore option and the Xandros Installation CD will detect a Xandros installation on /dev/hda2 say YES to the 1st question and NO to the 2nd question to rewrite the LILO boot sector, and now you can boot off your new Reiserfs filesystem.
_________________
Linux simply works for me...
Registered Linux User 384461


Last edited by aldube on Tue Nov 29, 2005 5:18 pm; edited 4 times in total
Back to top
View user's profile Send private message
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Fri Apr 08, 2005 3:04 pm    Post subject: Reply with quote

Example:
Copying partion data from one hard-drive to another hard-drive of different partion sizes. In this example (/hda1, /hda2, & /hda3) will be the new hard-drive placed in the computer as Master and (/hdb1, /hdb2 & /hdb3) will be the old hard-drive placed in the computer as Slave; you may need to consult your hard-drive manuals or consult a PC professional for hard-drive installation, as I canīt cover every possible scenario in hard-setup setup.

The easiest thing to do for partioning your new hard-drive is just to boot off you Xandros 3 Install CD pick the advanced options; donīt worry about what to select for Xandros components just move on to Hard-Drive partioning advanced option and setup the partions on hda and then write to disc then cancel Xandros 3 installation. You can at this point install Windows on /hda1 as c: drive.

So weīre booting off the PartImage Rescue CD again and at the command Prompt.
# mkdir /a
# mkdir /c
# mkfs -t reiserfs -f /dev/hda2 (optional: use if you didnīt select a filesystem during partitioning or wish to change filesystem type to Reiserfs)
# mount /dev/hda2 /a
# mount /dev/hdb2 /c
# cd /c
# tar lcf - .|(cd /a; tar xpvf - )
# mkfs -t swap /dev/hda3 (if /hda3 is to be swap your swap partion)
Keep in mind the fstab example above with mc if your changing the originally installed filesystem type.
Then reboot on you Xandros 3 CD and press Shift key when the option comes up and then select the Restore option and the Xandros Installation CD will detect a Xandros installation on /dev/hda2 & /dev/hdb2 pick /dev/hda2 say YES to the 1st question and NO to the 2nd question to rewrite the LILO boot sector, and now you can boot off your new Hard-Drive.
_________________
Linux simply works for me...
Registered Linux User 384461


Last edited by aldube on Tue Nov 29, 2005 5:17 pm; edited 3 times in total
Back to top
View user's profile Send private message
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Fri Apr 08, 2005 3:07 pm    Post subject: Reply with quote

This is an advanced how-to convert your Xandros Filesystem to the high performance SGI XFS:

Xandros 3 - SGI XFS filesystem installation how-to.
http://forums.xandros.com/viewtopic.php?t=12026&sid=13cac9697e80a146e7dcb4e6d60decc6

This how-to replaces a swap-partition with a swapfile:

How to make & use a Swapfile instead of a Swap Partion.
http://forums.xandros.com/viewtopic.php?t=13967&sid=13cac9697e80a146e7dcb4e6d60decc6
_________________
Linux simply works for me...
Registered Linux User 384461
Back to top
View user's profile Send private message
mike80808
Xanscended
Xanscended


Joined: 14 Apr 2003
Posts: 3891
Location: St. Louis, MO

PostPosted: Sun Apr 10, 2005 6:33 pm    Post subject: Reply with quote

You can use TAR to create multi-volume archives. However, it requires the GNU version of TAR on both the creation and the extraction side. See the -M option (--multi-volume) and the -L option (--tape-length). You may also want to use the --new-volume-script option to label the CD volumes properly.

The entire point of tar -- Tape ARchive -- was to support multiple volumes. To state that TAR is unable to do so is unequivocably false, and should not be continued.

However, that said, if you need multi-volume archives, the PKZIP format (i.e. zip/unzip) has long supported multi-volume archives as well.
_________________
Thanks for all the fishes, Xandros.
Back to top
View user's profile Send private message Visit poster's website
aldube
Xandrosianschwing


Joined: 02 Jan 2005
Posts: 2332
Location: Calgary, Alberta, Canada

PostPosted: Sun Apr 10, 2005 10:14 pm    Post subject: Reply with quote

mike80808 wrote:
You can use TAR to create multi-volume archives. However, it requires the GNU version of TAR on both the creation and the extraction side. See the -M option (--multi-volume) and the -L option (--tape-length). You may also want to use the --new-volume-script option to label the CD volumes properly.

The entire point of tar -- Tape ARchive -- was to support multiple volumes. To state that TAR is unable to do so is unequivocably false, and should not be continued.

However, that said, if you need multi-volume archives, the PKZIP format (i.e. zip/unzip) has long supported multi-volume archives as well.


Yep; TAR does support multiple volumes; however, itīs not as convinient to use as partimage; a value of --tape-length=716800 has to be used to equal 700 MB.

If you have any good examples of using multiple volumes or scripts, feel free post these as this is what this tutorial is for. Wink
_________________
Linux simply works for me...
Registered Linux User 384461
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.xandros.com Forum Index -> Tips & Tricks All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group