Advertisement
Nestor10

Proxmox snapnext.sh

May 27th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1. #!/bin/bash
  2. lastsnap_location=
  3.   # For VMs: /root/vm_lastsnap
  4.   # For CTs: /root/ct_lastsnap
  5. list_location=
  6.   # For VMs: /etc/pve/nodes/pve/qemu-server
  7.   # For CTs: /etc/pve/lxc
  8. snap_command=
  9.   # For VMs: "qm snapshot"
  10.   # For CTs: "pct snapshot"
  11. snap_suffix="auto_$(date +%Y%m%d) -description \"Autosnapped at $(date +%H:%M:%S)\""
  12. snapped=false
  13. first=false
  14. if [ -f $lastsnap_location ]; then
  15.   lastsnap=`cat $lastsnap_location`
  16. else
  17.   lastsnap=0
  18. fi
  19. for i in `ls $list_location | egrep -o '[0-9]{3,}'`; do
  20.   if [[ $first -eq false ]]; then
  21.     first=$i
  22.   fi
  23.   if (( $i > $lastsnap )); then
  24.     echo $snap_command $i $snap_suffix | /bin/sh
  25.     snapped=true
  26.     echo $i > $lastsnap_location
  27.     break
  28.   fi
  29. done
  30. if ! $snapped; then
  31.   echo $snap_command $first $snap_suffix | /bin/sh
  32.   echo $first > $lastsnap_location
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement