Last active
January 9, 2019 07:09
-
-
Save janglapuk/5b46c48044d81789d9e7c02ad335c507 to your computer and use it in GitHub Desktop.
vzdump backup script to Google Drive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; | |
then | |
echo "Usage: $0 <VMID>" | |
exit 1 | |
fi | |
BACKUPDIR="/var/lib/vz/dump" | |
# --------------------------------------------------------------- | |
echo "" | |
VZDUMPLOG=$(vzdump $1 -compress lzo) | |
if [ $? -ne 0 ]; | |
then | |
echo "ERROR: some error occured on vzdump process. Exiting..." | |
exit 2 | |
fi | |
# --------------------------------------------------------------- | |
BACKUPFILE=$(echo "$VZDUMPLOG" | grep -o "creating archive .*" | grep -oEI "'.*'" | sed -e "s/'//g") | |
BASENAME=$(basename "$BACKUPFILE" ".tar.lzo") | |
LOGFILE="$BACKUPDIR/$BASENAME.log" | |
GDRIVEPARENT=$(cat /root/backup/parent_id.txt) | |
echo "Backup file : $BACKUPFILE" | |
echo "Log file : $LOGFILE" | |
echo "Drive parent : $GDRIVEPARENT" | |
/usr/local/bin/gdrive upload -p "$GDRIVEPARENT" "$BACKUPFILE" | |
/usr/local/bin/gdrive upload -p "$GDRIVEPARENT" "$LOGFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment