/
osbackup
executable file
·57 lines (43 loc) · 1.23 KB
/
osbackup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# root check
if [ "$(id -u)" != "0" ]
then
>&2 echo "You should be root to do a successful backup!"
exit 1
fi
# create directory for metadata outputs
mkdir metadata 2>/dev/null
# create info file
echo This directory contains files with metadata for the recostruction. >metadata/README
# saving partition table
sfdisk -d > metadata/partitions 2>/dev/null
# saving block-device IDs
blkid > metadata/blkid
# physical volumes
pvscan -u > metadata/pvs 2>/dev/null
# back-up LVM configs
vgcfgbackup --file metadata/lvm 2>/dev/null
# save RAID (md) info
mdadm -Evs > metadata/md 2>/dev/null
# copy RAID array parameters
cp /proc/mdstat metadata/mdstat 2>/dev/null
# copy dm_crypt parameters
cp /etc/crypttab metadata/crypttab 2>/dev/null
# copy fstab for initial filesystems
cp /etc/fstab metadata/fstab
# save LUKS info
touch luks
rm luks
for file in /dev/mapper/*
do
info=`tools/lukstool shortinfo $file 2>/dev/null`
if [ "$info" != "" ]
then
echo $file $info >>metadata/luks
fi
done
# create archive
mkdir restore 2>/dev/null
tar cvpzf restore/root.tgz --exclude=`pwd`/restore --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/tmp $TAR_FLAGS /
# generate restore scripts
./generate-scripts.pl