arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GBackup, by HMR (need help)
#9
Ok, so, this is my backup code, you need to install drive first as following:
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.
#!/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.)


Messages In This Thread
GBackup, by HMR (need help) - by youssefbasha - 04-10-2018, 07:59 PM
RE: GBackup, by HMR (need help) - by tiwil - 04-11-2018, 01:41 AM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-11-2018, 06:18 AM
RE: GBackup, by HMR (need help) - by perry - 04-11-2018, 08:59 AM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-11-2018, 11:44 AM
RE: GBackup, by HMR (need help) - by perry - 04-11-2018, 11:53 AM
RE: GBackup, by HMR (need help) - by tiwil - 04-11-2018, 01:43 PM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-11-2018, 01:46 PM
RE: GBackup, by HMR (need help) - by tiwil - 04-11-2018, 03:35 PM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-11-2018, 03:47 PM
RE: GBackup, by HMR (need help) - by tiwil - 04-12-2018, 01:13 PM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-12-2018, 01:17 PM
RE: GBackup, by HMR (need help) - by perry - 04-12-2018, 07:36 PM
RE: GBackup, by HMR (need help) - by tiwil - 04-13-2018, 03:40 AM
RE: GBackup, by HMR (need help) - by youssefbasha - 04-18-2018, 07:37 AM

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting