Skip to content

Instantly share code, notes, and snippets.

@jmjuanes
Last active March 16, 2016 13:17
Show Gist options
  • Select an option

  • Save jmjuanes/dc15b53a23ddc711d988 to your computer and use it in GitHub Desktop.

Select an option

Save jmjuanes/dc15b53a23ddc711d988 to your computer and use it in GitHub Desktop.

Revisions

  1. jmjuanes revised this gist Mar 16, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gbackup.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    //Configuration
    var rclone = '/Users/jmjuanes/bin/rclone'; //Rclone path
    var exclude = '/srv/_bin/gbackup_exclude.txt'; //Exclude file
    var exclude = '/srv/.bin/gbackup_exclude.txt'; //Exclude file
    var command = '{rclone} sync {origin} gdrive:{remote} --exclude-from {exclude}'; //RClone command

    //Import dependencies
  2. jmjuanes created this gist Mar 11, 2016.
    46 changes: 46 additions & 0 deletions gbackup.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/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);
    4 changes: 4 additions & 0 deletions gbackup.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    {
    "remote": "path/",
    "exclude": [ ".git/**", ".gitignore", ".gitmodules", "node_modules/**", ".DS_Store" ]
    }