Personal portfolio - Mauricio Aznar

GDrive backups in ubuntu 18

 

Table of Content

Intro


GDrive commmand line installment


tutorials:


  1. Copy the latest release into folder
wget https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive_2.1.1_linux_386.tar.gz

  1. Unzip the Archive
tar -xvf gdrive_2.1.1_linux_386.tar.gz

  1. Perform authentication
./gdrive about

  1. Move utility to /usr/local/bin/gdrive so we can call it globally
mv gdrive-linux-x64 /usr/local/bin/gdrive

Write backup .sh script

#!/bin/sh

# Bail out if there are any errors
set -e

# The name of the database we're going to backup.
DB_NAME="inopack"

# The Google Drive Folder ID where database exports will be uploaded to
GDRIVE_FOLDER_ID="1waC1ESInU6SURm6WvbNDeocJppGhH0hZ"

# Date format for dadtes appended to database export files
DATE_FORMAT="%Y-%m-%d_%H:%M:%S"

# Options to pass to the mysqldump command
MYSQLDUMP_FILE_NAME="$DB_NAME-$(date +$DATE_FORMAT).sql"

# Perform mysqldump
/usr/bin/mysqldump -u root --password='root' "$DB_NAME" > "$MYSQLDUMP_FILE_NAME"

# Upload the newly created file to Google Drive
/usr/local/bin/gdrive upload --parent "$GDRIVE_FOLDER_ID" "$MYSQLDUMP_FILE_NAME"

# Delete mysqldump file
rm "$MYSQLDUMP_FILE_NAME"

Crontab

crontab -e
0 3 * * *  /bin/sh /home/mau/generate-inopack-backup.sh >> /home/mau/log 2>&1