04-11-2018, 03:35 PM
Ok, so, this is my backup code, you need to install drive first as following:
After using command "drive", you will be given a link from google. Open it, then login with your google account, you will get a "token" or verification code. Copy and paste it to the command line.
Example as following:
Ok, then you can use the following backup script.
Let me know if you're facing any errors (which shouldn't happened, already test it with my VPS.)
Code: (Select All)
cd /usr/bin
wget -O drive https://drive.google.com/uc?id=0B3X9GlR6EmbnMHBMVWtKaEZXdDg
chmod 755 drive
drive
After using command "drive", you will be given a link from google. Open it, then login with your google account, you will get a "token" or verification code. Copy and paste it to the command line.
Example as following:
Quote:abc@xyz:/usr/bin]# drive
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/aut...tate=state
Enter verification code:
Ok, then you can use the following backup script.
Code: (Select All)
#!/bin/sh
# file name as date
date=$(date +"%Y-%m-%d")
# backup folder
backupfolder="/home/YOUR USERNAME/backups"
backuptarget="/home /etc /var/www /usr/local" # folder to backup
# database
dbhost="localhost"
dbuser="YOUR DB USER"
dbpassword="YOUR DB PASSWORD"
# make directory if not exists
mkdir -p $backupfolder
mkdir -p $backupfolder/mysql
echo "Starting backup"
# backup database, thanks to HMR
databases=$(mysql --host="$dbhost" --user="$dbuser" --password="$dbpassword" -e "SHOW DATABASES;" 2>&1 | grep -v "Warning: Using a password" | tr -d "| " | grep -v Database)
for db in $databases; do
if [ "$db" != "information_schema" ] && [ "$db" != "performance_schema" ] && [ "$db" != "mysql" ] && [ "$db" != _* ] ; then
mysqldump --compress --host="$dbhost" --user="$dbuser" --password="$dbpassword" --events $db > $backupfolder/mysql/$db.sql 2>&1 | grep -v "Warning: Using a password"
fi
done
# compressing file
tar -cf $backupfolder/$date.tar.gz $backuptarget
echo "Backup done named $date.tar.gz"
echo "Starting upload to Google Drive"
# uploading file
drive upload --file $backupfolder/$date.tar.gz
echo "Done, removing local backup files"
# removing file
rm $backupfolder/$date.tar.gz
echo "Job done"
Let me know if you're facing any errors (which shouldn't happened, already test it with my VPS.)