Discussion:
Using dd to create (rotated) backups
(too old to reply)
W3
2007-07-05 18:12:09 UTC
Permalink
Hi there,

I would like to create a script that I can stick into my crontab which
creates something like this automatically every time it is run:

20070530-machinename-sda7.ext3.dd.gz

IE, year, month, day - machinename - physical drive - filesystem .dd.gz

Then I would like to set it to run once a month...

Can anyone help me with some resources? Will this be a very complicated
script? If everything else is too complicated, I would settle for just
having the date (in that order) in there :-)

Thanks so much everyone,

/Walter
Mike Anonymous Coward
2007-07-07 19:41:08 UTC
Permalink
Post by W3
Hi there,
I would like to create a script that I can stick into my crontab which
20070530-machinename-sda7.ext3.dd.gz
IE, year, month, day - machinename - physical drive - filesystem .dd.gz
Then I would like to set it to run once a month...
Can anyone help me with some resources? Will this be a very complicated
script? If everything else is too complicated, I would settle for just
having the date (in that order) in there :-)
Thanks so much everyone,
/Walter
Maybe (I didnt test... just a quick jab)

Well, figuring out the filesystem [type] might be more artistic,
but the fstab should say what it is... and that mgith be optional info.

#--------------------------------------------------------
part=/dev/sda7 # what to backup

### What is the fs type
p=${part//\//\\\/} # use \/ not just / (for awk)
t=`awk "/$p[ \t]/ { print \$3; }" < /etc/fstab` # the fs type

### What file to backup to
p=${part%%/.*} # just the last of the name "sda7"
filename=`date +%Y%m%d`-`hostname`-$p.$t.dd.gz

### Do the backup (better if that fs isnt mounted and in use!)
dd if=$part | gzip -9 > $filename
#---------------------------------------------------------

Using "dd bs=4096 if..." might make it faster... stick to a power of 2.
Bigger block sizes do better io.

Making backups is not useful if you cant restore.
You better test your backups! (periodically, if not every time)
Testing means "does restore really work"!

Loading...