Skip to content

Instantly share code, notes, and snippets.

@vcampitelli
Last active October 17, 2023 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vcampitelli/1b2ecf2131193625e46243df2c04c5c9 to your computer and use it in GitHub Desktop.
Save vcampitelli/1b2ecf2131193625e46243df2c04c5c9 to your computer and use it in GitHub Desktop.
Simple shell script that uses gdrive to upload files to Google Drive
#!/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