view · edit · history · print

Backup to a remote machine.

Ever wanted to backup partition data to a remote machine that has tape or DVD recorder?

Wel, under here i list some commands and examples that can help you. Be shure to read the notes at the bottom of the page before asking questions ;-) These commans can be run from another partition, from the local partion [not recommended] or from a rescue CD like SystemRescue or Knoppix Live.


Some of my favorite backup commands

  
INFOFILE="backup_debian_hda7_20041118"

# tar backup (with gzip mitigation trick, see FAQ)
mount /dev/hda7 /mnt
cd /mnt
tar -cvf - ./ 2>/tmp/${INFOFILE}.fileindex.txt | \
  gzip -1 | \
  ssh wvh@10.42.42.22 dd of=backupfiles/${INFOFILE}.tar.gz
cd ~
umount /mnt

# tar/untar backup (with dd mitigation trick, see FAQ)
tar -cvf - ./ | ssh vgb42 "cd /bitop2/vdfrs3; dd | tar xvf - "


# dd backup
fsck /dev/hda7 && \
  dd if=/dev/hda7 bs=8k | \
  gzip -1 | \
  ssh wvh@10.42.42.22 dd of=backupfiles/${INFOFILE}.dd.gz bs=8k

# create and transfer infofiles
fdisk -l /dev/hda > /tmp/${INFOFILE}.partinfo.txt
fdisk -l /dev/hda7 >> /tmp/${INFOFILE}.partinfo.txt
mkfs -n /dev/hda7 >> /tmp/${INFOFILE}.partinfo.txt
scp /tmp/${INFOFILE}.*.txt wvh@10.42.42.22:backupfiles/


dd backup and restore example

  
# first things first, getting and storing partition info

$ fdisk -l /dev/hda
Disk /dev/hda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        1539    12361986    c  W95 FAT32 (LBA)
/dev/hda2            1540        1952     3317422+   c  W95 FAT32 (LBA)
/dev/hda4            1953        7296    42925680    f  W95 Ext'd (LBA)
/dev/hda5            1953        2018      530113+  82  Linux swap
/dev/hda6            2019        2801     6289416   83  Linux
/dev/hda7            2802        3323     4192933+  83  Linux
/dev/hda8            3324        3845     4192933+  83  Linux
/dev/hda9            3846        4367     4192933+  83  Linux

$ fdisk -l /dev/hda8
Disk /dev/hda8: 4293 MB, 4293563904 bytes
255 heads, 63 sectors/track, 521 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

$ mkfs -n /dev/hda8
mke2fs 1.34 (25-Jul-2003)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
524288 inodes, 1048233 blocks
52411 blocks (5.00%) reserved for the super user
First data block=0
32 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

# dd backup of hda8

$ dd if=/dev/hda8 bs=8k | \
  gzip -1 | \
  ssh user@host dd of=hda8.dd.gz bs=8k

# dd restore of hda8 on hda9

$ ssh user@host dd if=hda8.dd.gz bs=8k | \
  gunzip | \
  dd of=/dev/hda9 bs=8k


tar ... untar example

  
example 1:
$ sudo su - root -c "cd ~appA; tar -cf - ./sql/" | \
  ssh -x user@some_remote_server \
  'sudo su - root -c "cd ~appB; tar -xf - "'

example 2:
root@srv2:/# ssh -x user@srv1 sudo tar -cf - /oracle/DB1/data1 | tar -xvf -


FAQ

Q: You use mkfs, isn't that dangerous?

A: Yes, but be carefull and always use the "-n" option for retrieving partion info purposes. The "mkfs -n" command only provides partition info (like alternate superblocks and blocksizes), it does NOT change anything!

Q: Whats up with the piping trough gzip and why do you use "-1"?

A: Hmm... That are 2 questions ;-) The "-1" option provides fast but minimal compression and gzip it is mainly used to controll the network traffic.

Lets explain...

I pipe trough gzip with the tar backup method becouse not every unix has the GNU tar which includes the "-z" option.

The second reason is that it also allows me to "regulate" the compression in function of network traffic and CPU load. Change the the compression value to your needs (man gzip) or if your UNIX(tm) has no gzip installed then use compress instead (to avoid confusion don't forget replacing the .gz extention to .Z for compress).

The reason to use gzip (or compress) with the dd backup method is to ensure the network tranfer does not mess up our 8k dd blocks. The word on the net says that this is not a problem on IRIX but it is on Linux systems, i don't know abouth other UNIX based systems but i guess it all depends on the network settings that are defined by default or are set by the admin.

Q: Whats up with the piping trough dd when using tar/untar?

A: as with the gzip piping trick the dd work-around can be used to catch a software bug. e.g. IBM problem case "IZ21474: TAR NOT WORKING WITH RSH/REXEC/SSH APPLIES TO AIX 5300-08".

Q: Can i use the dd method for Windows(tm) partitions?

A: Yes, but i recommend you also backup your MBR (master boot record), depending on what you plan to do "after" the backup ;-)

Example: dd if=/dev/hda of=/mnt/floppy/hda.mbr_backup bs=512 count=1

Q: With the tar/untar example you use single quotes at the end, why?

A: On some systems (like AIX) the cd is not accepted and the unpacking is done in the user directory instead of the one you try to access trough sudo! end.

admin · attr · attach · edit · history · print
Page last modified on August 02, 2009, at 03:36 AM