- FileSync is very basic implementation of .NET GoogleDriveAPI v3.
- It uploads a single file to Google Drive cloud storage, using a Google service account.
- It grants permission to this file to another Google Drive account.
- It is shipped with a tiny command line application.
- For the moment it is just an uploader, not a file syncing tool at all.
Table Of Contents
- Prerequisites
- Command Line Usage
- Scenario
- Automation / Periodical Execution
- Enhancements
- Build and Run from Source
- Third Party
- The released version is tested with Windows 10 and Ubuntu 20.04.
- You will need to create a google service account. Read this.
- A service account is a different account, it's not your own Google account.
- Service accounts have their own 15 GB Drive free space.
- It's not visible via a web interface or somewhere else (unless you get a list via API, which is not implemented in FileSync at the moment).
Jaxx.FileSync.exe
-c ["PATH_TO_CERTFILE\key.p12"]
-s ["[email protected]"]
[COMMANDS] [COMMANDS_OPTIONS]
- Global options are mandatory!
Jaxx.FileSync.exe
-c "C:\Users\mike\privatekeys\mikeskey.p12"
-s "[email protected]"
list
- -c ["PATH_TO_CERTFILE\key.p12"]
- Provide the full path and filename of the private certificate p12 file you've downloaded from google api console after you've created the service account.
- -s ["[email protected]"]
- Provide the mail account you've created for the service account.
- [COMMANDS] [COMMANDS_OPTIONS]
- commands and subcommands as list, create file, delete object (as follows)
Jaxx.FileSync.exe
[GLOBAL_OPTIONS]
create file
-g ["[email protected]"]
-f ["UPLOAD_FILE"]
-d ["root"]
- All options are mandatory!
- You have to use the -g option with your own drive space, otherwise you'd never ever have the chance to see your uploaded file again.
Jaxx.FileSync.exe
-c "C:\Users\mike\privatekeys\mikeskey.p12"
-s "[email protected]"
create file
-g "[email protected]"
-f "C:\Users\mike\Documents\list.txt"
-d "root"
- [GLOBAL_OPTIONS]
- see there
- create
- Simply calls the command to create (upload) an object.
- file
- Tells the create command to create (upload) a file object.
- -g ["[email protected]"]
- Grant permissions to the created object to another google drive user, so that he will be able to see the files in his own account's shared folder (grant it to yourself!)
- -f ["UPLOAD_FILE"]
- Full path to the file you'd like to upload.
- -d ["root"]
- The folder where the file should be created. The folder has to exist.
- Pass "root" if the file should be created in the root folder.
Starting with release 1.1.0 you can create folders in you drive storage.
Jaxx.FileSync.exe
[GLOBAL_OPTIONS]
create folder
-g ["[email protected]"]
-n ["NEW_FOLDER_NAME"]
-p ["PARENTFOLDER"]
- All options are mandatory!
- If you want to create folders in the root path, pass 'root' as parent folder.
- A parent folder has to exist if you want to create a child folder.
- Be aware that folder names need to be unique in your store, due to my hasty implementation.
Jaxx.FileSync.exe
-c "C:\Users\mike\privatekeys\mikeskey.p12"
-s "[email protected]"
create folder
-g "[email protected]"
-n "SharedDocuments"
-p "root"
- [GLOBAL_OPTIONS]
- see there
- create
- Simply calls the command to create an object.
- folder
- Tells the create command to create a folder object.
- -g ["[email protected]"]
- Grant permissions to the created object to another google drive user, so that he will be able to see the object in his own account's shared folder (grant it to yourself!)
- -n ["NEW_FOLDER_NAME"]
- Name of the new folder
- -p ["PARENTFOLDER"]
- Name of the parent folder ('root' for root folder)
Starting with release 1.2.0 you can list the content in your drive storage.
Jaxx.FileSync.exe [GLOBAL_OPTIONS] list
This will list all objects available in your storage:
[ObjectId] [mimeType] -> filename.ext, lastmodified
THE OBJECT ID IS THE LISTED ID WITHOUT THE SQUARE BRACKETS!
Jaxx.FileSync.exe -c "C:\Users\mike\privatekeys\mikeskey.p12" -s "[email protected]" list
Starting with release 1.2.0 you can delete single objects in your drive storage. To delete an object you'll need the object id you can gather with the list command.
Jaxx.FileSync.exe
-c "C:\Users\mike\privatekeys\mikeskey.p12"
-s "[email protected]"
delete object -i "7A-155DKmzQ-SGD9zync0cdK8LNz"
As in all calls before, pass the global options, followed by the command delete object the parameter -i and the object id. There is no differene between a file and a folder, they are all objects.
DELETE A FOLDER WILL DELETE ALL CONTENT IN THIS FOLDER, TOO! THERE WILL BE NO WARNING!
All options are mandatory!
Beeing a kind of backup tool, FileSync will run unattended for a while. To clean up old backups in the Drive storage you could use the "delete agedfiles" command (Release >= 1.2.0).
Jaxx.FileSync.exe
[GLOBAL_OPTIONS]
delete agedfiles
-a [AGE_IN_DAYS]
-f [PARENTFOLDER]
-k [DAYS_TO_KEEP]
-p
Jaxx.FileSync.exe -c "C:\Users\mike\privatekeys\mikeskey.p12" -s "[email protected]"
delete agedfiles -a 30 -f "mikesbackups" -k 10
- [GLOBAL_OPTIONS]
- see there (mandatory)
- delete agedfiles
- Calls the command
- -a [AGE_IN_DAYS] (mandatory)
- Files which are not modified since the passed count of days will be affected.
- -f [PARENTFOLDER] (mandatory)
- Just files in this folder will be affected.
- -k [DAYS_TO_KEEP] (opitonal)
- optional parameter, will prevent to delete this number of files, if they are the last ones which had have been modified - despite of having reached the given age. (see Scenario)
- -p (optional)
- Passing this optional parameter will enable the preview mode. Nothing will be deleted but you'll see what would be deleted.
Mike runs a little MySQL database on a Windows OS. Each night it creates a dump of the database to backup data. The drawback: Until now this backups were stored on the local hard drive. What happens if this disk crashes?
After throwing away other ideas Mike decided to upload an extra backup to Google Drive. But he didn't want to install Google Drive app on his server for reasons:
- Neither, he wants to log in with his own google account
- Nor, he wants to create a google account for the server user
- Nor, it would be guaranteed that the user is logged into the system all the time at all
He decided to create a google service account, authenticated by an email account and a private certification file (key.p12). To access his uloaded backups he grants his own google account the necessary permissions, so it will be visible in his own cloud drive in "shared files".
He created a little batch file which first creates the backup of the MySQL database and uploads the backuped file in a next script. The batch file is trigger via build in Windows Task Scheduler.
After a while his store grows and grows as more and more backups are uploaded. He decides, that he only wants to keep the backups from the last 30 days. But wait! What if the backups won't run for some days and Mike didn't notice this for any reason? So he decided, that he always want to keep the last 10 files.
As Mike in our scenario: Use the Windows Task Scheduler to automate FileSync.
Check the issues page on GitHub for further "nice to haves", feel free to create issues or to contribute.
- Microsoft Visual Studio 2019 Community Edition
- .NET 5.0
To build & run, run dotnet restore and dotnet run.
Released version is shipped with (and dotnet restore will restore the NuGet packages) the following third party libraries:
- Google.Apis.Drive.v3 & Google.Apis by Google Inc.
- .NET by Microsoft
- Autofac