diff --git a/deploy.sh b/deploy.sh index ea3eb1d..7257f69 100644 --- a/deploy.sh +++ b/deploy.sh @@ -98,6 +98,33 @@ if [[ $1 == "-ID" ]]; then # Get the machines IPv4 and IPv6 address. FN_get_IPaddr $2 + # Check if this is a snapshot operation + if [[ $3 == "-snapshot" ]]; then + # If no snapshot name given, abort. + if [[ -z $4 ]]; then + echo "$TAGSTR No snapshot name given!" + exit + fi + + # Check if the snapshot exists on proxmox for this VMID. + SNAPSHOT_LIST=$(ssh root@$PROXMOX_IP_ADDR "pct listsnapshot $2") + SNAPSHOT_LIST=$(echo "$SNAPSHOT_LIST" | awk '{print $1}' | grep $4) + if [[ -z $SNAPSHOT_LIST ]]; then + # Create a snapshot with this name. + echo "$TAGSTR Creating a snapshot called $4 for VMID $2!" + ssh root@$PROXMOX_IP_ADDR "pct snapshot $2 $4" + else + # Restore to the snapshot + echo "$TAGSTR Rollbacking VMID $2 to snapshot $4!" + ssh root@$PROXMOX_IP_ADDR "pct rollback $2 $4" + + echo "$TAGSTR Starting VMID $2!" + ssh root@$PROXMOX_IP_ADDR "pct start $2" + fi + echo "$TAGSTR $IPv4ADDR, $IPv6ADDR" + exit + fi + # Check if a script/dir was provided. if [[ -z $3 ]]; then # No script found, just return the ip address. @@ -106,7 +133,7 @@ if [[ $1 == "-ID" ]]; then else # A script/dir was found, verify it exists. if [[ -e $3 ]]; then - FN_copyandorexec $3 + FN_copyandorexec $3 $IPv6ADDR echo "$TAGSTR $IPv4ADDR, $IPv6ADDR" exit else diff --git a/readme.md b/readme.md index 7971309..1f5bab0 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ My collections of various scripts related to proxmox. These can be used to creat ## Deploy Script -A small wrapper which generates an Arch Linux based container (by default) and then runs a optional script. Also can provide the IP address of a container created using the Arch setup script. +A small wrapper which generates an Arch Linux based container (by default) and then runs a optional script. Also can provide the IP address of a container created using the Arch setup script. Note you must update the ```PROXMOX_IP_ADDR``` variable at the top of the script so the script knows where to SSH to. Also, this is intentionally configured such that the proxmox login is via ssh-key only. If you need to setup the SSH keys, instructions can be found [here](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2). @@ -15,6 +15,10 @@ deploy.sh # Outputs a container ID when complete. # Create an Arch Linux based container which then runs a script to init gogs. deploy.sh gogs.sh # Outputs a container ID when complete. +# Create a snapshot of a container and then restore to said snapshot. +deploy.sh -ID 101 -snapshot foo # Snapshot called foo was created. +deploy.sh -ID 101 -snapshot foo # Rolling back to snapshot foo. + # Just run a script to init gogs on an already existing container. deploy.sh -ID 101 gogs.sh # Returns nothing.