Best practice for Proxmox self-backup

Thanks for the script. I wonder if the restore has been tested to work, especially if the Proxmox node is part of a cluster ? In this case /etc/pve/ is on a shared filesystem (pmxcfs) and maybe restoring is not possible or may lead to undesired cluster-wide effects ?
 
If you have to restore a node from a cluster you'd just restore everything except files in /etc/pve and /var/lib/pve-cluster. Just (re-)join the node to the existing cluster and you should be fine. This is the cleanest and safest way not to run into any trouble later on. You don't want to mess with cluster files. Those in the backup will be older than current cluster files and will mess up the whole cluster most probably.

I want to improve the restore process. For now just untar the files in /var/tmp so everything from within the tar files is to be found under /var/tmp/var/tmp/etc, /var/tmp/var/tmp/root, /var/tmp/var/tmp/var/lib/pve-cluster.

The path "/var/tmp/" depends on the path that the files where packaged while processing the backup.

You can also untar the files to a desired location, but I do not recommend to just untar over any existing files as this might mess things up. This may only work without 2nd though if you have a single node setup.

Give it a try. You are welcome to submit code changes via GITHUB.
 
Thank you for your reply DerDanilo,
I switched the lines:

tar -cvf "$_filename1" /etc/*
tar -cvf "$_filename2" /var/lib/pve-cluster/*
tar -cvf "$_filename3" /root/*

to
tar -cvf "$_filename1" /etc/.
tar -cvf "$_filename2" /var/lib/pve-cluster/.
tar -cvf "$_filename3" /root/.

so tar will get all files/folder started with "."

Best regards
 
I actually changed my script to that but did not submit the changes. The script itself changed in many parts and I included a way of mantaining a certain amount of backup files and push them to a remote FTPS server. I will upload it when I have time.
 
Ich muss das Script bei Gelegenheit mal aufräumen und meinen neuen Code integrieren. Wenn ich dran denke poste ich hier auch wieder.
 
Slightly old thread but wanted to say... Thanks DerDanilo!

Just like the OP, I backup my VEs/CTs to a network storage location but wanted to save the "config" of the Proxmox VE installation.

This seems like functionality that should be baked into Proxmox: a Backup/Restore button for the node config as well as the ability to schedule the last and control the number of backup copies you have. Alas, I don't have much control over that.

As you said in your previous posts your script archives the critical folders for the system and is designed to be run as a cronjob but doesn't support controlling the number of saved backups. I wrote a simple script to purge old security camera footage that I am using the control the max age of the backup files. I'm linking it here in case anyone else might find it useful.

https://github.com/begleysm/ipcam-ftp-tools/blob/master/ftp_cleanup.sh

Basically just run the script in a cronjob (any frequency is fine but running it right after you run your DerDanilo backup script makes sense) in the form: "./ftp_cleanup.sh /mnt/pve/backups 7". This will delete any files older than 7 days at /mnt/pve/backups (as well as empty folders). Depending on how often you run the DerDanlio Backup Script and what # days you put in the ftp_cleanup.sh script you can control the number of backups you keep.

Keep in mind that this will recurse down to all files/folder under mnt/pve/backups so make sure your file structure is such that you don't delete any files you want to keep.
 
  • Like
Reactions: DerDanilo
Hi,

In my own opinion you do not need to re-invent the weel ;). If you need backup, you do not need to create a new tool for this. Use a tool that fit your needs and that has a good history (at least 3-4 years ).
A good candidate is rsnaphot and I can say that is a very good tool (it was save me in any situation when I need it , I used for many years on any server that I need to administer )
 
  • Like
Reactions: begleysm
Hi,

In my own opinion you do not need to re-invent the weel ;). If you need backup, you do not need to create a new tool for this. Use a tool that fit your needs and that has a good history (at least 3-4 years ).
A good candidate is rsnaphot and I can say that is a very good tool (it was save me in any situation when I need it , I used for many years on any server that I need to administer )

Thanks guletz. Wasn't aware of rsnapshot. I'll be looking into it.
 
Lets integrate it into my script. I also have some changes to submit.

I considered that first but my script is written in BASH so running them back to back was easier as a stop gap.

I actually think it would be better to get a "max number of backups" from the user and then, at the end of your script, search for files that match the "$_tdir/proxmox_backup_"$_HOSTNAME"_"XXXX-YY-ZZ".tar.gz" format and delete the oldest files beyond "max number of backups".

If you don't get to it first, I'll try and add this in when I get time.
 
  • Like
Reactions: DerDanilo
First off, thank you DerDanilo for your work.
I took your script and put it to good use on my Proxmox 5.2 setup.
Some minor changes were needed to use your script in a cronjob, I created a pull request on GitHub if you like to incorporate them.

Cleanup is done really quick and dirty for now using another shell script with this line doing the main work:
Code:
 ls -1tr *.tar.gz | head -n -5 | xargs -d'\n' rm -f --
Of course, this cleanup will break and possibly eat my children if some funny named files start to appear in the backup directory.
 
  • Like
Reactions: DerDanilo
Hi and thanks DerDanilo for your work!

Regrettably I'm having probs with the script.
Works perfectly well from command line but cron wont work (runs every hour for test reason):

Code:
12 * * * * /bin/echo | /prox_config_backup.sh

The only output I get is:

Code:
TERM environment variable not set.
Cleaning up

While TERM is set to xterm but shouldn't actually be needed (ignorable!?).
No idea why cron complains anway.

Please help a Linux noob.

Cheers,
daniello
 
Hi daniello,

you have to set the variable BACKUP_DIR in the head of the crontab file. Here my file:

Code:
# cat /etc/cron.d/pveconfigbackup
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
SHELL=/bin/bash
TERM=xterm
MAILTO="email@example.com"
BACKUP_DIR=/var/backups/pvebackup/config
# m h dom mon dow user  command
# Script erwartet Enter beim Ausfuehren
45 20 * * 6 root echo | /root/proxmox_config_backup.sh >> /var/log/pve-config-backup.log

Ulf
 
Thanks Ulf,

I am a bit confused due to line 1 of your Code .. but my crontab now looks like this:

Code:
BACKUP_DIR=/mnt/qbak
40 * * * * /bin/echo | /prox_config_backup.sh

Regrettably the situation hasn't changed.

One thing I notice .. I call /prox_config_backup.sh and you call /root/prox_config_backup.sh
I tried copied the script to /root .. but it didn't help.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!