Gentoo Archives: gentoo-user

From: YoYo Siska <yoyo@××××××.sk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Clone live system as a simple backup?
Date: Thu, 08 Mar 2012 12:27:48
Message-Id: 20120308122645.GB25729@ksp.sk
In Reply to: Re: [gentoo-user] Clone live system as a simple backup? by Joshua Murphy
1 On Wed, Mar 07, 2012 at 02:47:08PM -0500, Joshua Murphy wrote:
2 > On Wed, Mar 7, 2012 at 8:55 AM, <gandalf@××××××××××.uk> wrote:
3 > >> Hi,
4 > >>    I'm interested in the idea of cloning a live, complicated hardware
5 > >> system onto a single external hard drive as a simple backup. I would
6 > >> like this external drive to be completely bootable. What's the best
7 > >> way to approach doing this? I was considering just doing a Gentoo
8 > >> install from scratch but figured maybe there's a way to clone enough
9 > >> of the live system to get me there less painfully?
10 > >>
11 > >>    The system I'm playing with has five 500MB hard drives with most
12 > >> partitions in linked together in various forms of RAID. (1, 5 & 6)
13 > >> That said, the total storage that this system presents KDE and the
14 > >> users is about 600GB.
15 > >>
16 > >>    I have an external 1TB eSATA drive which is therefore large enough
17 > >> to hold everything on this system, albeit without the reliability of
18 > >> RAID which is fine for this purpose.
19 > >>
20 > >>    The system looks more or less like:
21 > >>
22 > >> /dev/sda1 -> /boot (50MB)
23 > >> /dev/sdb1 -> /boot copy
24 > >> /dev/sdc1 -> /boot copy
25 > >>
26 > >> c2stable ~ # df
27 > >> Filesystem     1K-blocks      Used Available Use% Mounted on
28 > >> rootfs          51612920  31862844  17128276  66% /
29 > >> /dev/root       51612920  31862844  17128276  66% /
30 > >> rc-svcdir           1024        92       932   9% /lib64/rc/init.d
31 > >> udev               10240       476      9764   5% /dev
32 > >> shm              6151284         0   6151284   0% /dev/shm
33 > >> /dev/md7       389183252 350247628  19166232  95% /VirtualMachines
34 > >> tmpfs            8388608         0   8388608   0% /var/tmp/portage
35 > >> /dev/sda1          54416     29516     22091  58% /boot
36 > >> c2stable ~ # cat /proc/mdstat
37 > >> Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5]
38 > >> [raid4]
39 > >> md6 : active raid5 sdb6[1] sdc6[2] sda6[0]
40 > >>       494833664 blocks super 1.1 level 5, 64k chunk, algorithm 2 [3/3]
41 > >> [UUU]
42 > >>
43 > >> md7 : active raid6 sdb7[1] sdc7[2] sda7[0] sdd2[3] sde2[4]
44 > >>       395387904 blocks super 1.2 level 6, 16k chunk, algorithm 2 [5/5]
45 > >> [UUUUU]
46 > >>
47 > >> md3 : active raid6 sdb3[1] sdc3[2] sda3[0] sdd3[3] sde3[4]
48 > >>       157305168 blocks super 1.2 level 6, 16k chunk, algorithm 2 [5/5]
49 > >> [UUUUU]
50 > >>
51 > >> md126 : active raid1 sdc5[2] sda5[0] sdb5[1]
52 > >>       52436032 blocks [3/3] [UUU]
53 > >>
54 > >> unused devices: <none>
55 > >> c2stable ~ #
56 > >>
57 > >>    /dev/md3 is a second Gentoo installation that doesn't need to be
58 > >> backed up at this time. md6 is an internal RAID used to back up md7
59 > >> daily. It doesn't need to be backed up, but if the machine totally
60 > >> failed killing all the drives that wouldn't survive so currently I
61 > >> back up md126 to md6 daily, and then back up md6 weekly to an external
62 > >> eSATA drive.
63 > >>
64 > >>    What I'd like to do is clone
65 > >>
66 > >> 1) /boot (sda1) including grub and everything required to make it bootable
67 > >> 2) back up the system portions of dev/md126 (/ )
68 > >> 3) Add some swap space on the external drive
69 > >> 4) back up /dev/md7 which is all of my VMs
70 > >> 5) back up /home to a separate partition on the external drive
71 > >> 6) back up some special things like /var/lib/portage/world and
72 > >> /usr/portage/packages
73 > >>
74 > >> My thought is that this drive is basically bootable, but over time
75 > >> gets out-of-sync with the system. However should the system fail I've
76 > >> got a bootable external drive with all the binary packages required to
77 > >> get it running again quickly. However I can always boot the drive, do
78 > >> an emerge -ek @world, and basically be back to where I am as of the
79 > >> last backup.
80 > >>
81 > >> The external drive will look something like:
82 > >>
83 > >> /dev/sdg1 -> /boot
84 > >> /dev/sdg2 -> swap
85 > >> /dev/sdg3 -> / (not including /home, /usr/portage/distfiles, etc)
86 > >> /dev/sdg5 -> /usr/portage/packages
87 > >> /dev/sdg6 -> /dev/md7
88 > >>
89 > >> etc....
90 > >>
91 > >>    I will of course have to modify grub.conf and /etc/fstab to work
92 > >> from this drive but that's no big deal.
93 > >>
94 > >>    What are folks best ideas about how to approach doing something like
95 > >> this?
96 > >>
97 > >> Thanks,
98 > >> Mark
99 > >>
100 > >>
101 > > Hi,
102 > >    Why don't you something like bind mount the folders you want to copy
103 > > and rsync them to the eSATA disk, after creating a similar partition
104 > > layout on it. Remember to exclude system files like /proc/*, /dev/*
105 > > and /sys/* as well as the ones you want to exclude yourself from the
106 > > rsync. When you want to sync the clone again just do the same again
107 > > and rsync the changes.
108 > >
109 > > Regards,
110 > > Derek
111 > >
112 > >
113 >
114 > As an added note on this, rsync's --one-file-system (-x) flag is handy
115 > for avoiding grabbing unneeded things, but will typically leave you
116 > without the base few device nodes needed to boot the backup, those can
117 > either be grabbed from a stage3, or created with (courtesy of Linux
118 > From Scratch's section "6.2.1. Creating Initial Device Nodes"):
119 >
120 > mknod -m 600 ${backup}/dev/console c 5 1
121 > mknod -m 666 ${backup}/dev/null c 1 3
122
123 The best way to copy a filesystem without any sub-mounts is to
124 mount-bind it to some directory and copy it from there:
125
126 mkdir /tmp/root
127 mount --bind / /tmp/root
128 rsync -a /tmp/root/ /mnt/backup/
129
130 Note that copying a rw filesystem (especially /) on a running system
131 isn't a very clean operation..
132
133 yoyo