Skip to content
Luis Gomes edited this page Feb 16, 2016 · 11 revisions

This guide assumes you are running under the root user. If you are running under another user please sjust paths as appropriated.

STEP 1 - Download the jdrivesync:

https://github.com/siom79/jdrivesync/releases version: jdrivesync-0.3.0-jar-with-dependencies.jar

wget https://github.com/siom79/jdrivesync/releases/download/jdrivesync-0.3.0/jdrivesync-0.3.0-jar-with-dependencies.jar

###STEP 2 - Remove any existing java version:

apt-get remove openjdk-6-* apt-get remove openjdk-7-*

###STEP 3 - Install Oracle Java 8 jdk: wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

mkdir -p /opt/jdk

tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100

update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

run: update-alternatives --display java

should display: java - auto mode link currently points to /opt/jdk/jdk1.8.0_05/bin/java /opt/jdk/jdk1.8.0_05/bin/java - priority 100 Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/java'.

run: update-alternatives --display javac

should display: javac - auto mode link currently points to /opt/jdk/jdk1.8.0_05/bin/javac /opt/jdk/jdk1.8.0_05/bin/javac - priority 100 Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/javac'.

###STEP 4 - Create the following directories: /opt/bkp_scripts/ /opt/backups/

###STEP 5 - Config Jdrivesync

Move the file jdrivesync-0.3.0-jar-with-dependencies.jar on step 1 to the /opt/bkp_scripts/ directory:

mv /root/jdrivesync-0.3.0-jar-with-dependencies.jar /opt/bkp_scripts/

Go to the folder bkp_scripts cd /opt/bkp_scripts

rename the file mv jdrivesync-0.3.0-jar-with-dependencies.jar jdrivesync.jar

create a directory on your Google drive that will be used for this initial sync (it can be removed afterwards)

Since you will be running jdrive for the first time it will ask you to setup the auth_token, to do that you run them following: java -jar jdrivesync.jar -u -l '/tmp' -r 'tempsync' --no-delete

you will be presented with something like this: root@vps205930:/opt/bkp_scripts# java -jar jdrivesync.jar -u -l '/tmp' -r 'tempsync' --no-delete Please point your browser to the following URL and copy the access token provided after having authorized this application to access your Google Drive: https://accounts.google.com/o/oauth2/auth?client_id=966859022671.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/drive.file%20https://www.googleapis.com/auth/drive.readonly%20https://www.googleapis.com/auth/drive.metadata.readonly%20https://www.googleapis.com/auth/drive.appdata%20https://www.googleapis.com/auth/drive.apps.readonly%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/drive.scripts Please enter the code:

Copy the url and paste it on the web browser to get the oauth code, copy the oauth code and paste it into the terminal and press enter. As of now a file will be created in the ~/ folder, this file is called .jdrivesync and contains the oauth token. THIS FILE SHOULD NOT BE DELETED.

###STEP 6 - Create the bash file for the backup instructions:

inside /opt/bkp_scripts we will be creating a file called backup.sh

use you preferred editor (I like vim, but you can use nano or vi)

vim backup.sh

and paste the following:

#!/bin/sh

WEBSITE="site_folder_name"

DATABASE="db_name"

DBUSER="root"

DBPW="password"

DATE='date +%d%m%y%H%M'

mysqldump -u $DBUSER -p${DBPW} $DATABASE | gzip > /opt/backups/dbbackup_${DATABASE}_${DATE}.bak.gz

tar czf /opt/backups/sitebackup_${WEBSITE}_${DATE}.tar -C / var/www/$WEBSITE gzip /opt/backups/sitebackup_${WEBSITE}_${DATE}.tar

find /opt/backups/site* -mtime +1 -exec rm {} \;

find /opt/backups/db* -mtime +1 -exec rm {} \;

sleep 10

java -jar /opt/bkp_scripts/jdrivesync.jar -u -l '/opt/backups/' -r 'syncdemo' --no-delete

STEP 7 - Create a CronJob

from the shell run: crontab -e

and past the following (this line assumes a backup every 30 minutes)

*/30 * * * * /opt/bkp_scripts/backup.sh >/dev/null 2>&1

Save the file and you are ready to go.

EXTRA: the same cronjob but with logging enabled */30 * * * * /opt/bkp_scripts/backup.sh > /opt/backup_log.log

EMAIL alerts soon

Clone this wiki locally