haertig |
09-16-2006 12:35 PM |
How to backup - an example
The question of how to backup your system comes up very frequently on these forums. I thought I would throw out an example for those who might be looking for help.
There are more ways to backup than you can shake a stick at. Below is not the best, nor the worst. Just an example that works for me. If others want to chime in with their personal backup scripts, that would be a great resource for people searching for different options/solutions.
There are some things specific to my system below that should be edited/deleted for different situations.
To backup, I run:
(1) <insert a DVD-RW in my drive>
(2) sudo mount /mnt/backup
(3) sudo /mnt/backup/backup.sh
(4) sudo umount /mnt/backup
Here's the script referenced above, "/mnt/backup/backup.sh" ...
Code:
# Create backup directory
DATE=`date +'%F'`
mkdir /mnt/backup/$DATE
cd /mnt/backup/$DATE || exit 1
# Partition, filespace and mount info
fdisk -l >fdisk-l.txt
df -h >df-h.txt
mount >mount.txt
cp /etc/fstab fstab.txt
# Installed devices info
lsusb >lsusb.txt
lspci -v >lspci-v.txt
cat /proc/bus/input/devices >input_devices.txt
cat /proc/bus/usb/devices >usb_devices.txt
# System, module and boot info
uname -a >uname-a.txt
lsmod >lsmod.txt
dmesg >dmesg.txt
# Most people probably don't have these next two files
cp /var/log/boot bootlog.txt
cp /usr/local/etc/system_info.txt system_info.txt
# Account info
cp /etc/passwd password.txt
cp /etc/group group.txt
# Network info
ifconfig -a >ifconfig-a.txt
netstat -nlptu | cut -c1-42,69- >netstat.txt
# LVM info - comment out this section if you don't use LVM
pvs >pvs.txt
vgs >vgs.txt
lvs >lvs.txt
pvscan >pvscan.txt
vgscan >vgscan.txt
lvscan >lvscan.txt
pvdisplay >pvdisplay.txt
vgdisplay >vgdisplay.txt
lvdisplay >lvdisplay.txt
mkdir lvm_metadata
cp /etc/lvm/backup/* lvm_metadata/.
# /proc info
cat /proc/cpuinfo >cpuinfo.txt
cat /proc/meminfo >meminfo.txt
find /proc/ide -name model -type f -print | xargs cat >ideinfo.txt
find /proc/scsi -name scsi -type f -print | xargs cat >scsiinfo.txt
# MBR and Track Zero info - modify if your HDDs are not hda & hdb
dd if=/dev/hda of=hda_mbr.bin bs=512 count=1
dd if=/dev/hda of=hda_track0.bin bs=512 count=63
dd if=/dev/hdb of=hdb_mbr.bin bs=512 count=1
dd if=/dev/hdb of=hdb_track0.bin bs=512 count=63
# Filesystem info - modify for your mounted filesystems
( ! cd / || tar czvf root.tar.gz . )
( ! cd /boot || tar czvf boot.tar.gz . )
( ! cd /usr || tar czvf usr.tar.gz . )
( ! cd /opt || tar czvf opt.tar.gz . )
( ! cd /var || tar czvf var.tar.gz . )
( ! cd /home || tar czvf home.tar.gz . )
# Set modes and timestamps
find . -type f -print | xargs chmod 444
find . -type d -print | xargs chmod 555
find . -print | xargs touch
# Burn a DVD - modify if your DVD burner is not hdc
growisofs -dvd-compat -Z /dev/hdc -r -v .
# All done
exit 0
|