Backing up configuration file to google drive automatically

Status
Not open for further replies.

icsy7867

Contributor
Joined
Dec 31, 2015
Messages
167
So I figured out a working solution and I thought I would share it. This is my first sort of "guide" so if I did something wrong or if it is not helpful to anyone I apologize! Still trying to figure out all the nuances...

  1. The first step is to create a cron-job backup of the config file for freenas. This is fairly easy to do and I followed cyberjock's post here: https://forums.freenas.org/index.php?threads/backup-config-file-every-night-automatically.8237

    You will want to create a script. I called my backupconf.sh and I placed it in /usr/bin but you can put it wherever you like. Don't forget to chmod +x it!

    My config backup is in my "Storage" pool, but you can also put this where ever you like. Mine was placed in /mnt/Storage/Data/ConfigBackup/
    Code:
    cp /data/freenas-v1.db /mnt/Storage/Data/ConfigBackup/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/ve$


    Set the cronjob to run as root and use

    Code:
    sh /usr/bin/backupconf.sh
    manually run it and make sure your backup appears in the correct path.


  2. You will need to download the gdrive binaries. These can be found here: https://github.com/prasmussen/gdrive

    Download the corresponding file. I used the x64 FreeBSD one.

  3. After you download the file, move it to /usr/local/bin
    Code:
    sudo mv drive /usr/local/bin


    I downloaded it onto a windows machine and put it on one of my CIFS shares. I think moved it via terminal. Also remember to chmod +x /usr/local/bin/drive afterwards!

  4. once this is done. You should be able to type "drive" into your terminal, and you should get some text in the terminal with a web URL link. Do not open this link yet (Although if you do it's okay). We just wanted to make sure that "drive" was working.

  5. Now that we confirmed the binary was installed, and your cron job is working. We need to add in the google drive uploading portion. For this we are going to edit /usr/bin/backupconf.sh again. Simply open it up and add:
    Code:
    FILENAME="/mnt/Storage/Data/ConfigBackup/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -$
    drive upload --file $FILENAME
    


    So your new file should look something like:
    Code:
    cp /data/freenas-v1.db /mnt/Storage/Data/ConfigBackup/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/ve$
    FILENAME="/mnt/Storage/Data/ConfigBackup/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -$
    drive upload --file $FILENAME


    This just stores the filename that will be created when you move the config file into a variable, and then that variable is passed to the drive command.

  6. The first time you run this script, you should get a link in the terminal output. Now we are going to take this link and put it into a web browser. It will take you to a google page where you need to allow access. Simply click the "Allow" button.

  7. After this you will received an authentication code. Copy this code, and paste it back into the terminal. It should be asking for it.

  8. That should be it! If you check your google drive, you should have the file on the top level. I haven't quite figured out how to specifically choose a directory to upload to yet. Still working on that. I hope this wasn't too hard to follow. I will try to add pictures and better explanations with time permitting.
 

depasseg

FreeNAS Replicant
Joined
Sep 16, 2014
Messages
2,874
Very nice!
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
Indeed, very nice.
Although the drive binaries have changed their command syntax. No biggie, you just need to remove the `--file` part.

Also, I added a directory to gdrive and used `drive upload --parent DIRECTORY_ID $FILENAME` just to make it easier for me to navigate gdrive.
 

chrisada

Explorer
Joined
Dec 1, 2015
Messages
58
Indeed, very nice.
Although the drive binaries have changed their command syntax. No biggie, you just need to remove the `--file` part.

Also, I added a directory to gdrive and used `drive upload --parent DIRECTORY_ID $FILENAME` just to make it easier for me to navigate gdrive.

Thanks, tofagerl. That makes it very tidy!
 

chrisada

Explorer
Joined
Dec 1, 2015
Messages
58
Since upgrading to 9.10 I've been getting these email from crown:

cp: (dd17351).db is not a directory
No valid arguments given, use 'gdrive help' to see available commands

Sent from my Nexus 6P using Tapatalk
 

Robert Smith

Patron
Joined
May 4, 2014
Messages
270
You want to encrypt your config database before uploading to Google. The database contains passwords.
 

mullcom

Explorer
Joined
Apr 29, 2012
Messages
67
Hello i am following this guide but i dont get it working...

when i type drive i get this.
drive: Command not found.

my files name is gdrive-freebsd-x64

But still when i type gdrive-freebsd-x64 i get this.
gdrive-freebsd-x64: Command not found.

Standing in /usr/local/bin#
-rwxr-xr-x 1 root wheel 7808096 Jan 22 21:36 gdrive-freebsd-x64*

And when i typing this.
/usr/local/bin# sh /usr/local/bin/gdrive-freebsd-x64
/usr/local/bin/gdrive-freebsd-x64: 1: Syntax error: Unterminated quoted string
/usr/local/bin/gdrive-freebsd-x64: 1: Syntax error: Error in command substitution

What i am doing wrong?
 

mullcom

Explorer
Joined
Apr 29, 2012
Messages
67
Hello i am following this guide but i dont get it working...

when i type drive i get this.
drive: Command not found.

my files name is gdrive-freebsd-x64

But still when i type gdrive-freebsd-x64 i get this.
gdrive-freebsd-x64: Command not found.

Standing in /usr/local/bin#
-rwxr-xr-x 1 root wheel 7808096 Jan 22 21:36 gdrive-freebsd-x64*

And when i typing this.
/usr/local/bin# sh /usr/local/bin/gdrive-freebsd-x64
/usr/local/bin/gdrive-freebsd-x64: 1: Syntax error: Unterminated quoted string
/usr/local/bin/gdrive-freebsd-x64: 1: Syntax error: Error in command substitution

What i am doing wrong?
I needed a Rebout of Freenas system !!! SOLVD :D
 

icsy7867

Contributor
Joined
Dec 31, 2015
Messages
167
awesome! I havent had to re-fiddle with this in a while, so it was probably going to be a little while before I could get it to work. I am glad you got it all figured out
 

mullcom

Explorer
Joined
Apr 29, 2012
Messages
67
something is wrong her. :(

./bkpconfig.sh
../bkpconfig.sh: 1: Syntax error: Unterminated quoted string
../bkpconfig.sh: 1: Syntax error: Error in command substitution
 
Status
Not open for further replies.
Top