Last active
August 10, 2017 21:19
-
-
Save edwardstock/1429c7c0a7d4f46170e58219cf4d5008 to your computer and use it in GitHub Desktop.
GoogleDrive files backup with "gdrive" https://github.com/prasmussen/gdrive
This file contains 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/sh | |
# Example cron usage: | |
# 0 12 * * MON /usr/bin/drive_backup /var/www/public/ >> /var/log/drive_backup.log | |
# ^every monday at 12:00PM ^path to backup on google drive ^stream redirect ^path to backup log | |
# Basic manual usage | |
# drive_backup /path/to/directory/or/file | |
# File names will contains full path and date for uniqueness. | |
# Example: i want to backup /var/www/public, file name will be: var_www_public_2017-03-03.tar.gz | |
# If you need to backup every few hours (for example), just change DATE variable to DATE=$(date '+%Y-%m-%d %H:%M:%S') | |
GDRIVE=/usr/sbin/drive #path to gdrive binary | |
GDRIVE_UPLOAD_ARGS="" | |
GDRIVE_BACKUP_ROOT_ID="0BwoxWs37__UNIQUE_DIRECTORY_ID" # your google drive unique directory id where will stored files | |
GDRIVE_BACKUP_MACHINE_ID=$(hostname) | |
DATE=$(date '+%Y-%m-%d') | |
TARGET=$(realpath "${1}") | |
if [ "${TARGET}" == "" ] | |
then | |
echo "Path to backup must be specified by first argument" | |
exit 1 | |
fi | |
TARGET_NAME=$(echo "${TARGET}" | sed -r 's/^(\/{1})(.*)$/\2/' | tr "/" "_") | |
TARGET_NAME="${TARGET_NAME}_${DATE}.tar.gz" | |
echo -e "Path to backup: ${TARGET}" | |
echo -e "Backup file name: ${TARGET_NAME}" | |
echo -e "\nArchiving files..." | |
tar -zcf "${TARGET_NAME}" "${TARGET}" | |
UPLOAD="${GDRIVE} upload --file ${TARGET_NAME} --parent ${GDRIVE_BACKUP_ROOT_ID}" | |
echo -e "${UPLOAD}" | |
${UPLOAD} | |
rm -rf "${TARGET_NAME}" | |
echo -e "\nComplete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment