Last active
          March 16, 2016 13:17 
        
      - 
      
 - 
        
Save jmjuanes/dc15b53a23ddc711d988 to your computer and use it in GitHub Desktop.  
    Do backups to Google Drive using RClone from command line
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env node | |
| //Remember to make the script executable | |
| //chmod u+x gbackup.js | |
| //Configuration | |
| var rclone = '/Users/jmjuanes/bin/rclone'; //Rclone path | |
| var exclude = '/srv/.bin/gbackup_exclude.txt'; //Exclude file | |
| var command = '{rclone} sync {origin} gdrive:{remote} --exclude-from {exclude}'; //RClone command | |
| //Import dependencies | |
| var execSync = require('child_process').execSync; | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| //Read the gbackup file | |
| var gson = require(path.join(process.cwd(), 'gbackup.json')); | |
| //Exclude file content | |
| var file = ''; | |
| //Build the exclude file | |
| for(var i = 0; i < gson.exclude.length; i++){ file = file + gson.exclude[i] + '\n'; } | |
| //Save the file | |
| fs.writeFileSync(exclude, file); | |
| //Replace the rclone path | |
| command = command.replace(/{rclone}/g, rclone); | |
| //Replace the origin path | |
| command = command.replace(/{origin}/g, process.cwd()); | |
| //Replace the remote path | |
| command = command.replace(/{remote}/g, gson.remote); | |
| //Replace the exclude path | |
| command = command.replace(/{exclude}/g, exclude); | |
| //Show command in console | |
| console.log(command); | |
| //Run the command | |
| execSync(command); | |
| //Remove the exclude file | |
| fs.unlinkSync(exclude); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "remote": "path/", | |
| "exclude": [ ".git/**", ".gitignore", ".gitmodules", "node_modules/**", ".DS_Store" ] | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment