Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How would you use tar to backup partitions?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
lnxmacusr
n00b
n00b


Joined: 02 Dec 2004
Posts: 23

PostPosted: Mon Feb 07, 2005 11:39 pm    Post subject: How would you use tar to backup partitions? Reply with quote

Hi all,

I have tried a couple of different applications such as ghost, partimage, acronis trueimage with very mixed results if any at all. All the issues may/can probably be attributed to me being a noob and all. Nevertheless, I was reading my Linux in a Nutshell book about tar, and was just wondering if it still feasible to use a tool like tar for backing up an entire partition?

Ideally I would boot the gentoo livecd, mount the partitions I want to backup, then tell tar from the livecd (if possible) to tar and bzip (or gzip) the partition on /dev/hdaX and save it there. I only have one dvd drive in the machine so tarring and immediately sending to dvd is out of the question.

Any assistance with this would be greatly appreciated.
Back to top
View user's profile Send private message
d_m
Guru
Guru


Joined: 12 Jun 2003
Posts: 570
Location: Philadelphia, PA, USA

PostPosted: Tue Feb 08, 2005 12:40 am    Post subject: Reply with quote

It's easy to just read out the raw partition, encrypt with ${COMPRESSION_PROGRAM} and then store the file for restoration. I wrote a bunch of backup scripts to do this at my job. Here is the basic idea:

Code:
dd if=/dev/hda4 bs=4096 | gzip > hda4.img.gz


In fact, if you are backing up to another machine, here is a nifty thing to try. On the machine you want to store the images on, do this:

Code:
nc -l -p 31337 -w 3 > hda4.img.gz


And on the machine you are backing up, run:

Code:
dd if=/dev/hda4 bs=4096 | gzip -c | nc ${OTHER_HOST} 31337


This will pass the data from /dev/hda4 through compression, then directly over a TCP connection (on port 31337) to the other machine, ${OTHER_HOST}, which will then write the data to the file hda4.img.gz.

It's much faster than transferring the files over SSH, and much easier than temporarily setting up FTP or RSH or something else.

Hope this helps.
_________________
The name that can be named is not the eternal name.
Back to top
View user's profile Send private message
lnxmacusr
n00b
n00b


Joined: 02 Dec 2004
Posts: 23

PostPosted: Thu Feb 10, 2005 2:39 am    Post subject: Reply with quote

d_m wrote:
It's easy to just read out the raw partition, encrypt with ${COMPRESSION_PROGRAM} and then store the file for restoration. I wrote a bunch of backup scripts to do this at my job. Here is the basic idea:

Code:
dd if=/dev/hda4 bs=4096 | gzip > hda4.img.gz


In fact, if you are backing up to another machine, here is a nifty thing to try. On the machine you want to store the images on, do this:

Code:
nc -l -p 31337 -w 3 > hda4.img.gz


And on the machine you are backing up, run:

Code:
dd if=/dev/hda4 bs=4096 | gzip -c | nc ${OTHER_HOST} 31337


This will pass the data from /dev/hda4 through compression, then directly over a TCP connection (on port 31337) to the other machine, ${OTHER_HOST}, which will then write the data to the file hda4.img.gz.

It's much faster than transferring the files over SSH, and much easier than temporarily setting up FTP or RSH or something else.

Hope this helps.



It sounds cool. Is this something I can do from the live/mounted root partition? Or will I have to startup Knoppix CD, then mount root partition and then dd it? Also please explain what the bs=4096 means? Is this block size? If so, how can I make sure exactly waht this number should be? Thanks for your help.
Back to top
View user's profile Send private message
d_m
Guru
Guru


Joined: 12 Jun 2003
Posts: 570
Location: Philadelphia, PA, USA

PostPosted: Thu Feb 10, 2005 6:24 pm    Post subject: Reply with quote

You can do this from a live partition (as long as you are reading from it). Restoring is another matter, but yeah, you can just read (as root) from the raw device, which shouldn't interfere with anything else.

If you're doing backups, though, you probably want to turn off any databases you have, etc. so that data isn't changing too much as you write it out (if this happens to be a commercial server).

bs is blocksize. 4096 is about 4 MB (4,096 bytes), which in my experience is fine. Basically, you want it large enough that your dd isn't sending you tiny pieces of data all the time (so that gzip can compress it well). I don't have anything more scientific than that to say about it than that.

Good luck.
_________________
The name that can be named is not the eternal name.
Back to top
View user's profile Send private message
lnxmacusr
n00b
n00b


Joined: 02 Dec 2004
Posts: 23

PostPosted: Fri Feb 18, 2005 12:12 am    Post subject: Reply with quote

d_m wrote:
You can do this from a live partition (as long as you are reading from it). Restoring is another matter, but yeah, you can just read (as root) from the raw device, which shouldn't interfere with anything else.

If you're doing backups, though, you probably want to turn off any databases you have, etc. so that data isn't changing too much as you write it out (if this happens to be a commercial server).

bs is blocksize. 4096 is about 4 MB (4,096 bytes), which in my experience is fine. Basically, you want it large enough that your dd isn't sending you tiny pieces of data all the time (so that gzip can compress it well). I don't have anything more scientific than that to say about it than that.

Good luck.



Thanks for your response/help. Sorry it took me so long to reply, been really busy. I will try what you have suggested and get back to the forum.
Back to top
View user's profile Send private message
Lajasha
Veteran
Veteran


Joined: 17 Mar 2004
Posts: 1040
Location: Vibe Central

PostPosted: Fri Feb 18, 2005 2:42 pm    Post subject: Reply with quote

Here is the script that I use to backup the system. I just make a cronjob for it.

Code:

#!/bin/bash
TODAY=`date '+%F'`
FILE_NAME=$TODAY.$1
EMAIL="admin@youremail.com"
SUB="Backup Finished"
DIR_NAME="/mnt/backups/$TODAY"
EXCLUDES="--exclude=/dev/* --exclude=/mnt/* --exclude=/proc/* --exclude=/sys/* --exclude=/var/cache/* --exclude=*tmp/* --exclude=/usr/portage/distfiles/*"
echo Creating Folder: $DIR_NAME
mkdir $DIR_NAME
echo Creating Tarball: $FILE_NAME.tar.gz
nice -n 19 tar $EXCLUDES / -cvzpf $DIR_NAME/$FILE_NAME.tar.gz 1>/dev/null 2>$DIR_NAME/$FILE_NAME.log
echo Creating Tar Logs: $FILE_NAME.log
echo Creating MD5 for Tarball: $FILE_NAME.tar.gz.md5
nice -n 19 md5sum $DIR_NAME/$FILE_NAME.tar.gz > $DIR_NAME/$FILE_NAME.tar.gz.md5
echo Creating Email Report
BODY=`cat $DIR_NAME/$FILE_NAME.log`
sendmail -t <<EOF
Subject: $SUB $FILE_NAME
To: $EMAIL
From: root@youremail.com

$BODY


This also emails you when it is done with any errors. It also takes one extra argument that goes to affect the way the file is name.
_________________
Come and play in my land
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
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