ProxMox Config Backups

4 Dec

ProxMox Config Backups

Submitted by dziemecki on Sun, 02/08/2015 – 13:50

I recently set up a ProxMox virtual host and was quite impressed with the features one can get in an open source virtualization tool. The feature list for ProxMox is long and impressive, but one thing oddly missing is a way to back up its own configuration. For those long versed in the ways of Linux administration, the solution is probably obvious, but in case it isn’t, here’s one way to do it.

Like just about every other Linux app in existence, most configuration is stored in the “/etc” sub-directory. My approach was to basically to archive that, and dump it to a mounted share on another server. And set up a cron job to do it without me having to worry about it.

To start off, create a text file where ever it makes sense for you and add this to it:# set vars _now=$(date +%Y-%m-%d.%H.%M.%S) # temporary storage directory _tdir=”/var/tmp” # permanent backups directory _bdir=”/mnt/backups/proxmox/config”

This is just setting the table, creating a time stamp and setting local and remote directories for the process. You’ll set the directories to what works for you.

Next, stop the services and give them a moment to finish:# stop host services /etc/init.d/pve-cluster stop /etc/init.d/pvedaemon stop /etc/init.d/vz stop /etc/init.d/qemu-server stop # give them a moment to finish sleep 10s

The meat of the script comes next, where the key folders are archived:# copy key system files _filename1=”$_tdir/proxmoxetc.$_now.tar” _filename2=”$_tdir/proxmoxpve.$_now.tar” _filename3=”$_tdir/proxmoxconfig.$_now.tar” tar -cvf “$_filename1” /etc/* tar -cvf “$_filename2” /var/lib/pve-cluster/*

Now, restart everything before you start the file moves:# restart services /etc/init.d/qemu-server start /etc/init.d/vz start /etc/init.d/pvedaemon start /etc/init.d/pve-cluster start # qm startall – if they don’t start otherwise

Finally, tar up the results, clean up the leftovers, and move everything to your backups folder.# archive the moved system file tar cvf “$_filename3” $_tdir/*.tar && rm “$_filename1” && rm “$_filename2” gzip “$_filename3” # Move config archive to backup folder mv “$_filename3.gz” “$_bdir/proxmoxconfig.$_now.tar.gz”

And that’s the whole script. I dropped mine in the home folder and kicked it off in crontab with:sh /home/pmconfigbak

On my machine, you end up with a GZipped file of about 2 megs with a name like “proxmoxconfig.2015-01-04.23.59.01.tar.gz”. Depending upon how you schedule it and the size of your server, that could eventually become a space issue so don’t forget to set up some kind of archive maintenance.

To restore, move the file back to proxmox with cp, scp, webmin, a thumb drive, whatever. I place it back into the /var/tmp directory from whence it came. To unpack:# Unpack the original backup tar -zxvf proxmoxconfig.2015-01-02.14.38.08.tar.gz # unpack the tared contents tar -xvf proxmoxpve.2015-01-02.14.38.08.tar tar -xvf proxmoxetc.2015-01-02.14.38.08.tar

If the services are running, stop them:etc/init.d/pve-cluster stop /etc/init.d/pvedaemon stop /etc/init.d/vz stop /etc/init.d/qemu-server stop

Copy the old content to the original directory:cp -avr /var/tmp/var/tmp/etc /etc cp -avr /var/tmp/var/tmp/var /var

And, finally, restart services:/etc/init.d/qemu-server start /etc/init.d/vz start /etc/init.d/pvedaemon start /etc/init.d/pve-cluster start

If nothing goes wrong, and you have separately restored the VM images using the default ProxMox process, you should be back where you started.

Let’s hope it never comes to that.

Tags: