1 |
On Wednesday 30 November 2005 1:59 pm, A. Khattri wrote: |
2 |
> |
3 |
> Im wondering if anyone has written a script (or maybe there's a tool to do |
4 |
> this) that will make binary packages of everything installed on a server |
5 |
> which can then be used to perform very quick restores in the event of a |
6 |
> major failure? |
7 |
> |
8 |
|
9 |
I use the following to do a quick and complete restore for a remote gentoo |
10 |
server at 1and1. |
11 |
|
12 |
|
13 |
---------------------------------------- |
14 |
| Linux Backup and Bare Metal Recovery | |
15 |
---------------------------------------- |
16 |
|
17 |
-- Backup |
18 |
|
19 |
1) save metadata about how the disk is partitioned. |
20 |
|
21 |
# sfdisk -l > /etc/partition.bak |
22 |
# cp /etc/fstab /etc/fstab.bak |
23 |
|
24 |
|
25 |
2) back up master boot record (MBR) |
26 |
|
27 |
# dd if=/dev/hda of=/etc/mbr.bak bs=512 count=1 |
28 |
|
29 |
|
30 |
3) back up the operating system: |
31 |
|
32 |
# mount /boot ## if its not already |
33 |
# cd / |
34 |
# tar -jcf --anchored --exclude '/sys' --anchored --exclude '/proc' |
35 |
--anchored --exclude '/lost+found' - / | ssh target "cat > |
36 |
filename.tar.bz2" |
37 |
|
38 |
TODO: ssh -> ftp for 1and1 |
39 |
|
40 |
|
41 |
-- Restore |
42 |
|
43 |
1) boot rescue mode ( debian 2.6 at 1and1 ) |
44 |
|
45 |
|
46 |
2) partition drive(s) |
47 |
|
48 |
# ssh backupserver 'cat /etc/partition.bak' |
49 |
Disk /dev/sda: 9729 cylinders, 255 heads, 63 sectors/track |
50 |
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting |
51 |
from 0 |
52 |
|
53 |
Device Boot Start End #cyls #blocks Id System |
54 |
/dev/sda1 * 0+ 8 9- 72261 83 Linux |
55 |
/dev/sda2 9 133 125 1004062+ 82 Linux swap / |
56 |
Solaris |
57 |
/dev/sda3 134 9728 9595 77071837+ 83 Linux |
58 |
/dev/sda4 0 - 0 0 0 Empty |
59 |
|
60 |
|
61 |
# sfdisk /dev/sda << EOF |
62 |
0,9,83,* |
63 |
9,125,82 |
64 |
134,9595,83 |
65 |
,,0; |
66 |
EOF |
67 |
notes: |
68 |
sfdisk reads lines of the form <start> <size> <id> <bootable> |
69 |
<c,h,s> <c,h,s> |
70 |
where each line fills one partition descriptor. |
71 |
|
72 |
|
73 |
3) create file systems |
74 |
|
75 |
# mke2fs /dev/sda1 |
76 |
# mke2fs -j /dev/sda3 |
77 |
# mkswap /dev/sda2 |
78 |
|
79 |
# mkdir /mnt/gentoo |
80 |
# mkdir /mnt/gentoo/boot |
81 |
|
82 |
# swapon /dev/sda2 |
83 |
# mount -t ext3 /dev/sda3 /mnt/gentoo |
84 |
# mount /dev/sda1 /mnt/gentoo/boot |
85 |
|
86 |
4) restore OS and data |
87 |
|
88 |
# cd /mnt/gentoo |
89 |
# ssh target "cat filename.tar.bz2" | tar jpvxf - |
90 |
notes: |
91 |
-j Decompress with bzip2 |
92 |
-p Preserve permissions |
93 |
-v Verbose |
94 |
-x Extract |
95 |
-f File |
96 |
|
97 |
TODO: ssh -> ftp for 1and1 |
98 |
|
99 |
5) restore MBR |
100 |
|
101 |
# dd if=/mnt/gentoo/etc/mbr.bak of=/dev/sda bs=512 count=1 |
102 |
notes: |
103 |
one could run grub-install --no-floppy /dev/sda instead. |
104 |
|
105 |
|
106 |
--end |
107 |
|
108 |
|
109 |
-- |
110 |
Michael Irey |
111 |
System Administrator |
112 |
|
113 |
...................................................................... |
114 |
SightWorks, Inc. |
115 |
5331 SW Macadam Avenue, Suite 348 |
116 |
Portland, Oregon 97239 |
117 |
|
118 |
Web: http://www.sightworks.com |
119 |
|
120 |
SightWorks : Creative Internet Technologies |
121 |
-- |
122 |
gentoo-server@g.o mailing list |