2

I'm trying to copy my live server OS installation locally on a machine here so if something goes wrong we have a backup. I've installed the same OS version that's on our live system on this server already, but I want to make sure I can copy all of the same packages and duplicate the environment as much as possible. This is a quick fix, not a permanent solution.

I have all the config files backed up on Jungle Disk as well as site files and all of that. But I want to mirror the packages that are installed as well and would like to be able to do with as little work as possible. Any advice?

update

Importing debconf selections There were 3 errors shown...

warning: Unknown type terminal, skipping line 56
warning: Unknown type error, skipping line 76
warning: Unknown type detect-keyboard, skipping line 252

Here are some snipplets from my file:

# 
tasksel tasksel/terminal        terminal

# Detecting your keyboard layout
console-setup   console-setup/detect    detect-keyboard

# Failure restarting some services for PAM upgrade
libpam0g        libpam0g/restart-failed error

I actually got about 8 other errors, all were Unknown type error and am concerned with the stability of this mirror if I proceed

Ben
  • 3,630
  • 17
  • 62
  • 93

3 Answers3

3

On Debian-derived systems like Ubuntu, it is possible to very closely duplicate the software installation from one machine to another by using the package management tools. Lets say that MachineA is the original server you want to mirror, and MachineB is the server that you want to become a mirror of MachineA. (All commands quoted here must be run as root.)

First, make sure that the debconf-utils package is installed on both MachineA and MachineB (run the following on both servers):

aptitude update && aptitude install debconf-utils

Next, on MachineA, take a copy of the current package state, and of the debconf database:

dpkg --get-selections  > /root/dpkg-selections.txt
debconf-get-selections > /root/debconf-selections.txt

Copy the two files from MachineA to MachineB, e.g.:

scp /root/{dpkg,debconf}-selections.txt MachineB:

Now on MachineB, load the debconf selections file

debconf-set-selections /root/debconf-selections.txt

load the package selections file

dpkg --clear-selections && dpkg --set-selections < /root/dpkg-selections.txt

and finally, run the package manager to update your system's software installations

aptitude install

Now all that remains is to move over any needed config files from /etc on MachineA to MachineB. This is best done manually, because there are certain files that need to be different on the two machines, even if they are to be mirrors of each other. For example, files like /etc/hostname, /etc/network/interfaces, and /etc/fstab reflect things about their respective local systems that may (or must) be different on another machine. To generate a list of config files to consider copying from MachineA to MachineB, you can use rsync in "dry run" mode, where nothing is actually copied, but the files that would have been copied are listed, e.g. (from MachineB):

rsync -rplgoDvn MachineA:/etc/ /etc

ADDENDUM

It is not unusual for warning and error messages to be generated by debconf-set-selections. I have seen them many times myself, and I don't know why they occur, but I can't remember ever finding that they indicated an actual instance of a broken configuration.

If you are skeptical, and wish to allay your fears, you can verify whether all package configurations are okay by the following procedure: Create a list of all the packages for which warnings/errors were generated, and then manually run dpkg-reconfigure package for each package in that list. If there are any genuine problems with a package, they should be exposed and/or repaired by the reconfigure operation.

Steven Monday
  • 13,019
  • 4
  • 35
  • 45
  • Thanks for the bode of confidence... though PHPMyAdmin/Nagios didn't carry over and it wasn't on one of those lines that threw an error. – Ben Dec 08 '10 at 21:12
  • Things like databases and other packages that store things at runtime in their own datafiles will require special attention to migrate over to your mirror. I did mention the need to migrate over config files from `/etc`, but some packages have other stores of data or configuration that also need to be transferred over, and the details of how to effect those transfers will necessarily be package-dependent. – Steven Monday Dec 08 '10 at 21:49
  • Will using `rsync` sync all of my SSH users and home directories and mysql users/permissions? – Ben Dec 09 '10 at 14:30
  • I guess I didn't fully realize the scope of your original question, so the migration of users and their data is something I didn't cover in my answer. Yes, `rsync` can copy over all user files while preserving their ownerships and permissions settings. Just be certain that you've gotten all the system configs from `/etc` migrated over first, so that the users and groups are identical on both machines. – Steven Monday Dec 09 '10 at 16:49
2

I would, personally, treat this as just a backup opportunity rather than trying to replicate the system to another live running system. Just copy the whole new system to the old system using rsync or rdiff-backup. The benefit of rdiff-backup is that you could have multiple copies of the data easily.

An example rsync backup-like command would be, on the origin server:

rsync -a --exclude=/proc/ --exclude=/dev/ --exclude=/sys/ / root@backup:/path/to/backups/origin-root/

That'll make a FULL copy of the system on the destination. From there you can always recover any configuration you need, without worrying about overwriting configurations you need to preserve on the new server (e.g.: fstab, hosts, hostname, networking, udev persistent net rules, etc...).

Sean Reifschneider
  • 10,370
  • 3
  • 24
  • 28
0

On the old machine:

dpkg --get-selections >/tmp/mypackagelist

Copy the file to the backup machine and:

cat mypackagelist | xargs apt-get -y install

(This has to be done as superuser).

More can be found at this old question.

Hamish Downer
  • 9,142
  • 6
  • 36
  • 49