Google Cloud Storage Nearline Personal Linux Desktop Backup

By | 2016/11/22

Backup data to the cloud for cheap with Google Cloud and Nearline storage. I use Google Cloud Storage Nearline to backup my desktop, openmediavault NAS, servers, and more. Here is how I do it!


1. First, sign in here. It may prompt to setup billing if that has not been done:

https://console.cloud.google.com


2. Next, create a project, and then create a cloud storage bucket.

For example, my project is called ‘personal-backup’ and an example bucket for this demo is ‘something_bkup’, nearline storage class.


3. Ok once a bucket has been created, next install the app gsutil:

$ sudo pip install gsutil

4. After installing, run gsutil config to generate authorization. This will give a link to click on to authorize access to the google cloud account.

$ gsutil config

5. Next, create a small script (and sudo chmod +x to make executable) which will specify which directories to backup to the bucket. The options below will work like rsync to keep the backup in sync with local.

(There are other gsutil options available if desired – see the help info.)

Example backup script file name and location:

/usr/local/bin/gcbackup

And contents of /usr/local/bin/gcbackup for user jsmith:

#!/usr/bin/env bash
#
# Backup selected directories to a GoogleCloud Nearline bucket
#
# Example daily cron:
# @daily /usr/local/bin/gcbackup >/dev/null 2>&1
#

# Directories to backup to the cloud 
dir=( "/home/jsmith/Documents" "/home/jsmith/Music" "/home/jsmith/syncthing" "/home/jsmith/Pictures" "/home/jsmith/Videos" )

# Bucket name 
bucket=something_bkup

# Backup specified directories!
for i in "${dir[@]}"; do      
    /usr/local/bin/gsutil -m rsync -r -d $i gs://$bucket/$(hostname)$i
done

6. Add a daily cron:

$ crontab -e

# backup to google cloud nearline
@daily /usr/local/bin/gcbackup >/dev/null 2>&1

Done.


This can even be used to backup servers, a NAS, or any Linux directories on any rig. For example this is backing up /var/backups and /var/www for a host:

#!/usr/bin/env bash
#
# Backup selected directories to a GoogleCloud Nearline bucket
#
# Example daily cron:
# @daily /usr/local/bin/gcbackup >/dev/null 2>&1
#

# Directories to backup to the cloud 
dir=( "/var/backups" "/var/www" )

# Bucket name 
bucket=something_bkup

# Backup specified directories!
for i in "${dir[@]}"; do      
    /usr/local/bin/gsutil -m rsync -r -d $i gs://$bucket/$(hostname)$i
done


As with any service, be sure to review the rates, fees, and charges before starting.

Thanks,

2 thoughts on “Google Cloud Storage Nearline Personal Linux Desktop Backup

  1. Scott Miller Post author

    I’ve got under a TB of data backup, cost is ~$8 / month. Thanks,

    Reply
  2. Scott Miller Post author

    Extra note:

    The -d means DELETE! -d keeps your source in sync with the bucket. If you desire to keep all backups, including files deleted locally, leave out -d in your backup script. Rock on,

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.