Corsinvest / cv4pve-autosnap

Automatic snapshot tool for Proxmox VE
https://www.corsinvest.it/cv4pve
GNU General Public License v3.0
413 stars 51 forks source link

Can this be made possible to run locally on the proxmox server shell? #71

Closed chrcoluk closed 1 year ago

chrcoluk commented 1 year ago

It seems to be a requirement to run it remotely.

franklupo commented 1 year ago

Hi, you can run everywhere.

Best regards

turrini commented 1 year ago

Hi, to achieve redundancy, this is what I'm doing:

Have a directory structure like this in any of the hosts:

/opt/tools/bin/cv4pve-autosnap           (binary)
/opt/tools/etc/cron.d/cv4pve-autosnap    (crontab file)
/opt/tools/scripts/cv4pve-autosnap.sh    (shell script)

Link the crontab so the system cron can reach and execute

ln -s /opt/tools/etc/cron.d/cv4pve-autosnap /etc/cron.d/

Install syncthing on all hosts to keep /opt/tools synchronized automatically

(syncthing.net -> apt-get install syncthing, enable it and configure)

The script (/opt/tools/scripts/cv4pve-autosnap.sh):

#!/bin/bash

if [[ -z "$2" ]]; then
    echo "Usage: $(basename $0) <label> <# keep> [all]"
    exit 1
fi

snapshot_user="autosnap@pve"
snapshot_password="XXXXXXXXXXX"

label="$1"
keep="$2"
[[ -z "$3" ]] && what="all" || what="$3"

# Only run if this host is the cluster master
is_master=$(/usr/sbin/ha-manager status | grep -m 1 -o "^master $(hostname -s)")
if [[ ! -z "${is_master}" ]]; then
    /opt/tools/bin/cv4pve-autosnap \
        --host=127.0.0.1 \
        --username=${snapshot_user} \
        --password=${snapshot_password} \
        --vmid="${what}" \
        snap \
        --label="${label}" \
        --keep="${keep}" \
        --only-running
fi

The cron file (/opt/tools/etc/cron.d/cv4pve-autosnap):

# Snapshot
0 0     * * *   root   /opt/tools/scripts/cv4pve-autosnap.sh daily 5 all
0 */1   * * *   root    /opt/tools/scripts/cv4pve-autosnap.sh hourly 8 all

This is far from the best way to do it probably, but it works for me :)

franklupo commented 1 year ago

You can run cv4pve-autosnap outside the cluster or in a vm or ct.