Skip to content

Instantly share code, notes, and snippets.

@xunleii
Last active December 23, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xunleii/09df336dcaa65ea4e0ec41b4f3abb35b to your computer and use it in GitHub Desktop.
Save xunleii/09df336dcaa65ea4e0ec41b4f3abb35b to your computer and use it in GitHub Desktop.
dump2ftp - Send Proxmox dump with FTP
#!/bin/bash
# Authors: Alexandre NICOLAIE <pheonyx>
# Description: Script to send and remove automatically Proxmox dump with FTP (for Online.net)
# Arguments: dump2ftp <ftp server> <ftp user> <ftp password> <pushbullet api key> <day before clean> <vzdump path>
SERVER="$1"
USER="$2"
PASSWD="$3"
API_KEY="$4"
DAY_AGO="$5"
VZDUMP="$6"
current=$(date +%Y_%m_%d)
previous=$(date --date="$DAY_AGO days ago" +%Y_%m_%d)
cd $VZDUMP
files=$(find . | grep $current)
echo "- Get numbers for report"
nufile=$(echo $files | wc -l)
giga_unit=$((1024 * 1024))
nusize=0
for file in $files; do nusize=$(($nusize + $(du $file | cut -f1))); done
nusize=$(($nusize / $giga_unit))
echo "- Remove to old folders"
/usr/bin/ftp -n -i $SERVER <<END
user $USER $PASSWD
binary
passive
cd $previous
mdelete *
cd ..
rmdir $previous
quit
END
echo "- Upload files"
/usr/bin/ftp -n -i $SERVER <<END
user $USER $PASSWD
binary
passive
mkdir $current
cd $current
mput *$current*.gz
quit
END
echo "- Send report with Pushbullet API"
pushbullet_title="Dump routine from $(hostname)@$(hostname -i)"
pushbullet_message="Upload $nufile backup(s) ($nusize Go) to $USER@$SERVER"
json='{"body":"'$pushbullet_message'","title":"'$pushbullet_title'","type":"note"}'
curl \
--header "Access-Token: $API_KEY" \
--header 'Content-Type: application/json' \
--data-binary "$json" \
--request POST \
https://api.pushbullet.com/v2/pushes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment