Best practice for Proxmox self-backup

micro

Active Member
Nov 28, 2014
58
13
28
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 ?
 
Jan 21, 2017
322
45
33
Berlin
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.
 

fabio vilardo

New Member
Dec 28, 2017
2
3
3
47
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
 
Jan 21, 2017
322
45
33
Berlin
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.
 

begleysm

New Member
Jun 1, 2018
11
3
3
44
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

guletz

Renowned Member
Apr 19, 2017
1,271
190
68
Brasov, Romania
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

begleysm

New Member
Jun 1, 2018
11
3
3
44
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.
 

begleysm

New Member
Jun 1, 2018
11
3
3
44
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

xmirakulix

New Member
Jul 20, 2018
1
1
3
120
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

daniello

New Member
Oct 13, 2018
17
0
1
50
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
 

ulf.kosack

Member
Jan 28, 2012
21
3
23
Wachtberg
www.edvnet-uk.com
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
 

daniello

New Member
Oct 13, 2018
17
0
1
50
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 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 your own in 60 seconds.

Buy now!