Last active
October 17, 2023 17:31
-
-
Save vcampitelli/1b2ecf2131193625e46243df2c04c5c9 to your computer and use it in GitHub Desktop.
Simple shell script that uses gdrive to upload files to Google Drive
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 | |
# Main vars | |
DATE=$( date '+%Y-%m-%dT%H-%M-%S' ) | |
JSON_CREDENTIALS_FILE=arquivo-credenciais.json ### CHANGE THIS! | |
PARENT_FOLDER_ID=xxxx ### CHANGE THIS! | |
# Upload function | |
gdrive_upload() { | |
/path/to/gdrive --service-account $JSON_CREDENTIALS_FILE upload --no-progress --parent $PARENT_FOLDER_ID --delete $FILE | |
} | |
# Compressing some folder | |
FILE=/tmp/$DATE-files.tar.gz | |
tar zcvf $FILE -C /path/to/some/folder . | |
gdrive_upload | |
# MySQL dump | |
FOLDER=/tmp/"$DATE"-sql | |
mkdir $FOLDER | |
# Removing information_schema and performance_schema databases | |
databases=$(mysql -N -e 'show databases' | grep -Ev "information_schema|performance_schema") | |
for dbname in $databases; do | |
echo "$dbname"; \ | |
mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > "$FOLDER"/"$dbname".sql; \ | |
done | |
FILE=/tmp/$DATE-sql.tar.gz | |
tar zcvf $FILE -C $FOLDER . | |
rm -rf $FOLDER | |
gdrive_upload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment