3 minute read

UPDATE: Google Drive doesn’t automatically empty trash. So if you use this method and files get moved to trash because you deleted them from your NAS or created a new version then your Google Drive storage will explode and it’s all in the trash. See the section on cleanup for the solution.

Synology Cloud Sync is very useful and particularly powerful when paired with Hyper Backup. However, there are some more complex scenarios that aren’t supported if you’re interested in encrypted backups to your favorite cloud provider. For instance:

  1. Selecting a root folder on the synology that is encrypted
  2. Backing up a mix of encrypted folders and non-encrypted folders

Unfortunately, Synology Cloud Sync does not support backup of encrypted directories directly to Google Drive. There is an option to encrypt the contents upon upload, but this doesn’t work if you are backing up a synology-encrypted folder. However, it is fairly straightforward to work around this and use Google Drive to store backups encrypted using Synology.

Here’s how to do it.

Note: This was tested on Synology DSM 6.X

Create a new Shared Directory

Create an unencrypted Shared Directory on the Synology. See instructions here.

Let’s call it GDrive_Backup for now.

Enable Cloud Sync

Enable Cloud Sync for your Google Drive account using this new directory. See the instructions here

Copy encrypted contents

Copy encrypted shared directory contents to GDrive_Backup.

$ cp -rf /volume2/@your_enc_shared_dir@ /volume2/GDrive_Backup/enc_backup

You may want to remove all @eaDir folders if they exist before backing up

$ cd /volume2/your_un_enc_shared_dir
$ find . -name @eaDir -print0 | xargs -0 /bin/rm -rf

Automate the backup

You can use rsync and the Synology Task Scheduler to automate the backup

Here’s an example script you can add to the Synology Task Scheduler (via the gui in Control Panel). Put the following (modified for your use case) in a file somewhere you can reference in the Task Scheduler.

$ mkdir -p /volume2/tmp/.tmp_rsync
$ rsync -av -T /volume2/tmp/.tmp_rsync /volume2/@your_enc_shared_dir@ /volume2/GDrive_Backup/backup_name

Caution: Make sure you don’t use /tmp as the temporary rsync location since there’s not enough space for large files

Verify backup from Google Drive

Note: the following was done on a Ubuntu Linux instance

  1. Download entire folder from Google Drive and unzip (Not in home directory if using encryption in Ubuntu!)
  2. Get a copy of encrypted and/or unencrypted contents directly from Synology
  3. Fix renaming issue from Google Drive (it doesn’t like when a file ends in a “.”)
    $ cd path/to/unzipped/GDrive/download
    $ find . -name '*_TailCharacterConflict' -print0 | xargs -0 rename 's/\.\_.*_TailCharacterConflict$/\./'
    
  4. unencrypt and mount new directory
  5. compare contents
    $ diff -rq /path/to/orig /path/to/gdrive_version
    

How to do a bulk empty of Google Drive trash

Google Drive doesn’t automatically empty trash. So if you use this method and files get moved to trash because you deleted them from your NAS or created a new version then your Google Drive storage will explode and it’s all in the trash.

Going to the webpage and emptying the trash could take forever, so I found a great project that does this programmatically. I don’t have it scripted to run on a regular basis yet, but that would be easily doable. The project is called rclone - it’s open source and super useful.

At the time of writing the Google Drive cleanup feature wasn’t available in the official release yet, so I downloaded the beta. Then I ran the following:

$ rclone config #this prompted sharing a login with the appropriate Google account which you have to do
$ rclone cleanup remote:

That’s it. Within a few minutes I noticed the total used storage on Google Drive starting draw down to a more reasonable number and within an hour or two it matched what I expected from my NAS backup.

Updated: