Giter Club home page Giter Club logo

proxmox-stuff's Introduction

Proxmox stuff

This is a collection of stuff that I wrote for Proxmox. Its possble to use the Ansible roles I wrote or to use the bash scripts for the backup & restore tasks.


Ansible

Small Ansible playbook and role collection for Proxmox related stuff.

prox_config_backup

I just wrote this script quick and dirty. Some people use it on a daily basis (including me).

There might be a PBS backup feature to backup PVE cluster config in the near future provided by the Proxmox team. But since this was only mentioned on the roadmap we still have to wait.

Meanwhile I manage all PVE nodes with Ansible and usually have no need to restore configuration unless all cluster nodes failed at once. But having a full cluster config backup is still useful and makes PVE admins sleep well at night (or day).

The script must be run as root, and can be run from cron or an interactive terminal.

Backup

  • Download the script
    cd /root/; wget -qO- https://raw.githubusercontent.com/DerDanilo/proxmox-stuff/master/prox_config_backup.sh
  • Set the permanent backups directory environment variable export BACK_DIR="/path/to/backup/directory" or edit the script to set the $DEFAULT_BACK_DIR variable to your preferred backup directory
  • Make the script executable chmod +x ./prox_config_backup.sh
  • Shut down ALL VMs + LXC Containers if you want to go the safe way. (Not required)
  • Run the script ./prox_config_backup.sh

Notification

The script supports healthchecks.io notifications, either to the hosted service, or a self-hosted instance. The notification sends during the final cleanup stage, and either returns 0 to tell Healthchecks that the command was successful, or the exit error code (1-255) to tell Healthchecks that the command failed. To enable:

  • Set the $HEALTHCHECK variable to 1
  • Set the $HEALTHCHECK_URL variable to the full ping URL for your check. Do not include anything after the UUID, the status flag will be added by the script.

Restore

โ— ONLY USE THIS SCRIPT ON THE SAME NODE / PROXMOX VERSION, OTHERWISE IT WILL BREAK YOUR FRESH PROXMOX INSTALLATION. IT WILL ALSO FAIL IF YOU ARE RUNNING A CLUSTER! โ—

For more info also see #5.

Bash Scripts

Cron

To set up a automatic cron job on a monthly (/etc/cron.weekly or /etc/cron.daily can be used to!) schedule, running the prox_config_backup script, follow these steps:

wget https://raw.githubusercontent.com/DerDanilo/proxmox-stuff/master/prox_config_backup.sh -O /etc/cron.monthly/prox_config_backup

Change DEFAULT_BACK_DIR="/mnt/pve/truenas_backup/pve" and MAX_BACKUPS=5 to the values you want!

Optional: Execute run-parts to see if it contains errors:

run-parts -v --test /etc/cron.monthly

Manually

On my machine, you end up with a GZipped file of about 1-5 MB with a name like "proxmox_backup_proxmoxhostname_2017-12-02.15.48.10.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 where it came.

# Unpack the original backup
tar -zxvf proxmox_backup_proxmoxhostname_2017-12-02.15.48.10.tar.gz
# unpack the tared contents
tar -xvf proxmoxpve.2017-12-02.15.48.10.tar
tar -xvf proxmoxetc.2017-12-02.15.48.10.tar
tar -xvf proxmoxroot.2017-12-02.15.48.10.tar

# If the services are running, stop them:
for i in pve-cluster pvedaemon vz qemu-server; do systemctl stop $i ; done

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

# And, finally, restart services:
for i in qemu-server vz pvedaemon pve-cluster; do systemctl start $i ; done

If nothing goes wrong, and you have separately restored the VM images using the default Proxmox process.
You should be back where you started. But let's hope it never comes to that.

Script

  • Download the script
    cd /root/; wget -qO- https://raw.githubusercontent.com/DerDanilo/proxmox-stuff/master/prox_config_restore.sh
  • Make the script executable chmod +x ./prox_config_restore.sh
  • Run the script ./prox_config_restore.sh proxmox_backup_proxmoxhostname_2017-12-02.15.48.10.tar.gz

Sources

http://ziemecki.net/content/proxmox-config-backups

proxmox-stuff's People

Contributors

blebo avatar bootsie123 avatar chrisg661 avatar derdanilo avatar djsni avatar hdcore avatar imnxnyer avatar keonik1 avatar peterge1998 avatar phidauex avatar ryanwinter avatar sonst-was avatar stefanlk avatar tdeppner avatar xmirakulix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxmox-stuff's Issues

Encrypted Backup File

Hi,

would it be possible to modify the backup script that it generates a password encrypted backup file?

Thanks,

Thomas

Info on backup step large or minor step ?

Hi Thanks for your script, it look quite interesting and what i was looking for to properly understand. Actually, is the whole proxmox is only into these 3 folders that are being restore/backup : /etc /var /root ?
Mean, i install a fresh proxmox iso and simply put back the 3 folder and it's all get to where i was ? Or the backup is more just for small change made..?

minus the vm that need to be re-import of course..
Thanks

Ceph support

I am currently starting to fiddling around to create some proper proxmox backup solution for our servers.
We are using ceph as storage, that is not yet supported at this script.

I have no idea yet if I can use this script (if so I pr the changes), if not I wanted to to archive at least what is needed to get ceph support. Might be helpful for someone.

We are currently doing a hacky approach that works, for us, too. The excludes are important, the OSDs are typical including TB of data.

tar -cPvf "/path/backup.tar" \
  --exclude='/var/lib/ceph/osd/ceph*/*' \
  --exclude='/var/lib/ceph/tmp' \
  /etc/ \
  /root/ \
  /var/lib/ceph/ \
  /var/lib/corosync/ \
  /var/lib/pve-cluster/

For restore these files are important, otherwise your OSDs won't work.

/etc/ceph/
/etc/systemd/system/ceph-mgr.target.wants/ceph-mgr@*.service
/etc/systemd/system/ceph-mon.target.wants/ceph-mon@*.service

Hint: script restores /etc/fstab - not good on new setups

Hi,
thanks for this little helper! I used it to restore/build a new single node setup.

One thing to keep in mind:
the script would also restore /etc/fstab, which in case of a new setup would contain different mounts with different UUIDs. So it is required to exclude /etc/fstab from the restore process, otherwise your fresh install might not boot after the restore.

File Not Found?

Disclaimer, I suck with linux and Proxmox, but Im trying to learn.

I was interested in this to backup my node and following the readme. I can run the first command to get the script, and run the 2nd command to set the directory. However, when running the chmod command, I'm receiving "chmod: cannot access './prox_config_backup.sh': No such file or directory". It's displaying the script, but doesnt seem to be saving it.

Is there a command Im missing? The readme seems straightforward, but there's obviously something Im missing as it's not saving the file?

/etc/pve is completely empty

I run your script and I am not getting the point: the folder /etc/pve is completely empty in the file:
proxmoxetc.2023-03-10.19.30.04.tar

I followed your wiki and while all other folders are ok, this one - quite important I believe - is empty
what am I doing wrong?

Screenshot 2023-03-10 at 19 43 19

Screenshot 2023-03-10 at 19 41 28

Status Information at beginning of output

Hi,

I am running the backup script as Cron job and receive an automatically generated E-Mail everytime.
Would it be possible to modify the script, that it prints the status of the backup in the very first line of the E-Mail, so that it is easier to check the overall backup result? I think the script should buffer all output into a temporary variable and at the end output the status first and then print the buffered content.

Thanks,

Thomas

Script not working when running from crontab

I can execute the script manually without any issue but when I added to cron to run everyday it is not generating any backup file and it is sending and error to healthchecks.io but I cannot see any error in syslog or the output of the script, has anyone manage to get the script working from cron?

Cant restore

Grub screen after:

Unpack the original backup

tar -zxvf proxmox_backup_proxmoxhostname_2017-12-02.15.48.10.tar.gz

unpack the tared contents

tar -xvf proxmoxpve.2017-12-02.15.48.10.tar
tar -xvf proxmoxetc.2017-12-02.15.48.10.tar
tar -xvf proxmoxroot.2017-12-02.15.48.10.tar

If the services are running, stop them:

for i in pve-cluster pvedaemon vz qemu-server; do systemctl stop $i ; done

Copy the old content to the original directory:

cp -avr /var/tmp/var/tmp/etc /etc
cp -avr /var/tmp/var/tmp/var /var
cp -avr /var/tmp/var/tmp/root /root

And, finally, restart services:

for i in qemu-server vz pvedaemon pve-cluster; do systemctl start $i ; done

Error message running the script

Hi,

I get the following error running the script:

tar: /var/lib/pve-cluster/.: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

Any idea?

EOF issue

I met following problem when tried to execute backup script in Proxmox VE 5.1

root@proxmox:~# ./prox_config_backup.sh
./prox_config_backup.sh: line 115: warning: here-document at line 28 delimited by end-of-file (wanted `EOF')
./prox_config_backup.sh: line 116: syntax error: unexpected end of file

I removed all space characters before EOF and script started to work fine.

function description {
    clear
    cat <<EOF
        Proxmox Server Config Backup
        Hostname: "$_HOSTNAME"
        Timestamp: "$_now"
        Files to be saved:
        "/etc/*, /var/lib/pve-cluster/*, /root/*"
        Backup target:
        "$_bdir"
        -----------------------------------------------------------------
        This script is supposed to backup your node config and not VM
        or LXC container data. To backup your instances please use the
        built in backup feature or a backup solution that runs within
        your instances.
        For questions or suggestions please contact me at
        https://github.com/DerDanilo/proxmox-stuff
        -----------------------------------------------------------------
        Hit return to proceed or CTRL-C to abort.
EOF
    read dummy
    clear
}

I read somewhere that tabs (not spaces) should work with indentation, but I didn't test it.

Save installed apt packages and automatically reinstall them after recovery

If a proxmox node fails it would be nice to automatically reinstall all apt packages that were originally installed. The backup script could do this.

An easy way is described here
https://askubuntu.com/questions/1092567/how-to-get-package-list-from-one-pc-and-install-that-on-another-pc
https://askubuntu.com/questions/17823/how-to-list-all-installed-packages

Save all currently installed packages and repository keys with

sudo dpkg --get-selections > installed-packages
sudo apt-key exportall > repo-keys

In the recovery script install the packages with

sudo apt-get install dselect
sudo apt-key add repo-keys
sudo dpkg --set-selections < installed-packages
sudo apt-get dselect-upgrade -y

Maybe automatic installation is no good idea, as some packages might be outdated. But at least saving the list of previously installed packages would help to reconstruct the node manually.

Question

Does this script from DerDanilo also help after a ssd crash of the proxmox system? Means after reinstalled a new proxmox on a new ssd.

Can i re-create all VMs and CTs with the script (restore)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.