Skip to content

Instantly share code, notes, and snippets.

@genothomas
Forked from glowinthedark/RsyncBackup.js
Created March 24, 2022 16:30
Show Gist options
  • Save genothomas/701ad62dd46a94736f409dc75d4ee5ea to your computer and use it in GitHub Desktop.
Save genothomas/701ad62dd46a94736f409dc75d4ee5ea to your computer and use it in GitHub Desktop.

Revisions

  1. @glowinthedark glowinthedark revised this gist Aug 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/osascript -l JavaScript
    // ^^^^ COMMENT OUT/REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
    // ^^^^ COMMENT/REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
    // The SHEBANG is only needed if the file is executable and is run from a terminal with `./RsyncBackup.js`

    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
  2. @glowinthedark glowinthedark revised this gist Aug 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/osascript -l JavaScript
    // ^^^^ REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
    // ^^^^ COMMENT OUT/REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
    // The SHEBANG is only needed if the file is executable and is run from a terminal with `./RsyncBackup.js`

    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
  3. @glowinthedark glowinthedark revised this gist Aug 8, 2021. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/usr/bin/osascript -l JavaScript
    // ^^^^ REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
    // The SHEBANG is only needed if the file is executable and is run from a terminal with `./RsyncBackup.js`

    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
    // 2. Click the top-left dropdown which says 'AppleScript' and select 'JavaScript'
    @@ -12,19 +13,19 @@ app.includeStandardAdditions = true


    app.displayAlert("Rsync Backup Wizard v 0.21", {
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue",
    cancelButton: "Cancel",
    withIcon: "caution"
    withIcon: "caution"
    })

    var cmd_find_rsync;

    if (app.doShellScript('echo $SHELL') == '/bin/zsh') {
    cmd_find_rsync = 'source ~/.zshrc || true && which -a rsync';
    cmd_find_rsync = 'source ~/.zshrc || true && which -a rsync | uniq';
    } else {
    cmd_find_rsync = 'source ~/.bashrc || true && which -a rsync';
    cmd_find_rsync = 'source ~/.bashrc || true && which -a rsync | uniq';
    }

    output = app.doShellScript(cmd_find_rsync);
    @@ -134,9 +135,9 @@ var cmd = String(rsyncPath)
    + " --exclude 'node_modules'"
    + " --exclude 'Saved Application State'"
    + " '"
    + String(sourceFolder)
    + "\/' "
    + "'"
    + String(sourceFolder)
    + "\/' "
    + "'"
    + String(targetFolder) + "'";

    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
    @@ -149,11 +150,11 @@ var confirmationResponse = app.displayDialog("Press Continue to execute the foll
    cmd = String(confirmationResponse.textReturned)

    app.displayAlert(cmd, {
    message: "The rsync command will be started in the terminal",
    message: "The rsync command will be started in the terminal",
    buttons: ["Cancel", "🚀 Start Backup!"],
    defaultButton: "🚀 Start Backup!",
    cancelButton: "Cancel",
    withIcon: "caution"
    withIcon: "caution"
    })

    var terminal = Application('Terminal');
  4. @glowinthedark glowinthedark revised this gist Aug 8, 2021. 1 changed file with 14 additions and 8 deletions.
    22 changes: 14 additions & 8 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    #!/usr/bin/osascript -l JavaScript
    // ^^^^ REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^

    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
    // 2. Click the top-left dropdown which says 'AppleScript' and select 'JavaScript'
    // 3. Under menu File pick Export
    @@ -8,7 +11,7 @@ var app = Application.currentApplication()
    app.includeStandardAdditions = true


    app.displayAlert("Rsync Backup Wizard v 0.2", {
    app.displayAlert("Rsync Backup Wizard v 0.21", {
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue",
    @@ -45,7 +48,7 @@ var targetFolder = app.chooseFolder({
    // sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"

    var cmd = String(rsyncPath)
    // + " --checksum" TAKE TOO LONG!!!
    + " --checksum"
    + " -av"
    + " --progress"
    + " --ignore-errors"
    @@ -102,15 +105,15 @@ var cmd = String(rsyncPath)
    + " --exclude '/System/Library/Caches'"
    + " --exclude '/System/Library/Extensions/Caches'"
    + " --exclude '/Users/Guest'"
    + " --exclude 'Autosave\ Information'"
    + " --exclude 'Autosave Information'"
    + " --exclude 'Backups.backupdb'"
    + " --exclude 'Cache'"
    + " --exclude 'Desktop\ DB'"
    + " --exclude 'Desktop\ DF'"
    + " --exclude 'Desktop DB'"
    + " --exclude 'Desktop DF'"
    + " --exclude 'DiagnosticReports*'"
    + " --exclude 'Library/Caches'"
    + " --exclude 'Library/Containers'"
    + " --exclude 'Library/Group\ Containers'"
    + " --exclude 'Library/Group Containers'"
    + " --exclude 'Library/LanguageModeling'"
    + " --exclude 'Library/Logs'"
    + " --exclude 'Library/Mail/AvailableFeeds'"
    @@ -129,8 +132,11 @@ var cmd = String(rsyncPath)
    + " --exclude 'lost+found'"
    + " --exclude 'MobileBackups.trash'"
    + " --exclude 'node_modules'"
    + " --exclude 'Saved\ Application\ State'"
    + " '" + String(sourceFolder) + "\/' '"
    + " --exclude 'Saved Application State'"
    + " '"
    + String(sourceFolder)
    + "\/' "
    + "'"
    + String(targetFolder) + "'";

    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
  5. @glowinthedark glowinthedark revised this gist Apr 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ var targetFolder = app.chooseFolder({
    // sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"

    var cmd = String(rsyncPath)
    // + " --checksum" TOO LONG!
    // + " --checksum" TAKE TOO LONG!!!
    + " -av"
    + " --progress"
    + " --ignore-errors"
  6. @glowinthedark glowinthedark revised this gist Apr 5, 2021. 1 changed file with 108 additions and 5 deletions.
    113 changes: 108 additions & 5 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -7,19 +7,30 @@
    var app = Application.currentApplication()
    app.includeStandardAdditions = true

    app.displayAlert("Rsync Backup Wizard", {

    app.displayAlert("Rsync Backup Wizard v 0.2", {
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue",
    cancelButton: "Cancel",
    withIcon: "caution"
    })

    var choices = ["/usr/bin/rsync", "/usr/local/bin/rsync"];
    var cmd_find_rsync;

    if (app.doShellScript('echo $SHELL') == '/bin/zsh') {
    cmd_find_rsync = 'source ~/.zshrc || true && which -a rsync';
    } else {
    cmd_find_rsync = 'source ~/.bashrc || true && which -a rsync';
    }

    output = app.doShellScript(cmd_find_rsync);

    var rsyncPath = app.chooseFromList(choices, {
    rsync_paths = output.match(/[^\r]+/g);

    var rsyncPath = app.chooseFromList(rsync_paths, {
    withPrompt: "Select the rsync binary path:",
    defaultItems: ["/usr/bin/rsync"]
    defaultItems: [rsync_paths[0]]
    });

    var sourceFolder = app.chooseFolder({
    @@ -30,7 +41,97 @@ var targetFolder = app.chooseFolder({
    withPrompt: "Please select the TARGET:"
    });

    var cmd = String(rsyncPath) + " --progress -av --exclude '.DS_Store*' --exclude .fseventsd --exclude '.Spotlight-V100*' --exclude '.TemporaryItems*' --exclude '.Trashes*' --exclude '.Trash*' --exclude 'Cache*' --exclude 'Saved Application State*' --exclude 'Logs*' --exclude 'DiagnosticReports*' --exclude '.journal*' --exclude '.journal_info_block*' --exclude 'lost+found*' --exclude 'Autosave Information' --exclude 'Library/Containers' --exclude 'Library/Group Containers' --exclude 'Library/Logs' '" + String(sourceFolder) + "\/' '" + String(targetFolder) + "'";
    // TODO: include output of:
    // sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"

    var cmd = String(rsyncPath)
    // + " --checksum" TOO LONG!
    + " -av"
    + " --progress"
    + " --ignore-errors"
    + " --no-compress"
    + " --whole-file"
    + " --ignore-existing"
    + " --exclude '.cache'"
    + " --exclude '.com.apple.backupd.mvlist.plist'"
    + " --exclude '.docker'"
    + " --exclude '.DocumentRevisions-V100'"
    + " --exclude '.DS_Store*'"
    + " --exclude '.electron'"
    + " --exclude '.fseventsd'"
    + " --exclude '.hotfiles.btree'"
    + " --exclude '.journal*'"
    + " --exclude '.journal_info_block*'"
    + " --exclude '.MobileBackups'"
    + " --exclude '.MobileBackups.trash'"
    + " --exclude '.Spotlight-V100'"
    + " --exclude '.TemporaryItems*'"
    + " --exclude '.Trash'"
    + " --exclude '.Trashes'"
    + " --exclude '.vol'"
    + " --exclude '/automount'"
    + " --exclude '/cores'"
    + " --exclude '/dev'"
    + " --exclude '/home'"
    + " --exclude '/net'"
    + " --exclude '/Network'"
    + " --exclude '/private/etc/kcpassword'"
    + " --exclude '/private/Network'"
    + " --exclude '/private/tftpboot'"
    + " --exclude '/private/tmp'"
    + " --exclude '/private/var'"
    + " --exclude '/private/var/automount'"
    + " --exclude '/private/var/db/com.apple.backupd.backupVerification'"
    + " --exclude '/private/var/db/dhcpclient'"
    + " --exclude '/private/var/db/dyld'"
    + " --exclude '/private/var/db/dyld/shared_region_roots'"
    + " --exclude '/private/var/db/efw_cache'"
    + " --exclude '/private/var/db/fseventsd'"
    + " --exclude '/private/var/db/Spotlight'"
    + " --exclude '/private/var/db/Spotlight-V100'"
    + " --exclude '/private/var/db/systemstats'"
    + " --exclude '/private/var/folders'"
    + " --exclude '/private/var/lib/postfix/greylist.db'"
    + " --exclude '/private/var/log'"
    + " --exclude '/private/var/run'"
    + " --exclude '/private/var/spool/cups'"
    + " --exclude '/private/var/spool/fax'"
    + " --exclude '/private/var/spool/uucp'"
    + " --exclude '/private/var/tmp'"
    + " --exclude '/private/var/vm'"
    + " --exclude '/System/Library/Caches'"
    + " --exclude '/System/Library/Extensions/Caches'"
    + " --exclude '/Users/Guest'"
    + " --exclude 'Autosave\ Information'"
    + " --exclude 'Backups.backupdb'"
    + " --exclude 'Cache'"
    + " --exclude 'Desktop\ DB'"
    + " --exclude 'Desktop\ DF'"
    + " --exclude 'DiagnosticReports*'"
    + " --exclude 'Library/Caches'"
    + " --exclude 'Library/Containers'"
    + " --exclude 'Library/Group\ Containers'"
    + " --exclude 'Library/LanguageModeling'"
    + " --exclude 'Library/Logs'"
    + " --exclude 'Library/Mail/AvailableFeeds'"
    + " --exclude 'Library/Mail/Metadata/BackingStoreUpdateJournal'"
    + " --exclude 'Library/Mail/V2/MailData/AvailableFeeds'"
    + " --exclude 'Library/Mail/V2/MailData/BackingStoreUpdateJournal'"
    + " --exclude 'Library/Mail/V2/MailData/Envelope*'"
    + " --exclude 'Library/Metadata/CoreSpotlight'"
    + " --exclude 'Library/Mirrors'"
    + " --exclude 'Library/PubSub'"
    + " --exclude 'Library/Safari/HistoryIndex.sk'"
    + " --exclude 'Library/Safari/Icons.db'"
    + " --exclude 'Library/Safari/WebpageIcons.db'"
    + " --exclude 'Library/Updates'"
    + " --exclude 'Logs'"
    + " --exclude 'lost+found'"
    + " --exclude 'MobileBackups.trash'"
    + " --exclude 'node_modules'"
    + " --exclude 'Saved\ Application\ State'"
    + " '" + String(sourceFolder) + "\/' '"
    + String(targetFolder) + "'";

    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
    defaultAnswer: cmd,
    @@ -51,4 +152,6 @@ app.displayAlert(cmd, {

    var terminal = Application('Terminal');
    terminal.activate();
    delay(4)

    terminal.doScript(cmd);
  7. @glowinthedark glowinthedark revised this gist Mar 31, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    var app = Application.currentApplication()
    app.includeStandardAdditions = true

    var result1 = app.displayAlert("Rsync Backup Wizard", {
    app.displayAlert("Rsync Backup Wizard", {
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue",
  8. @glowinthedark glowinthedark revised this gist Mar 30, 2021. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -26,17 +26,12 @@ var sourceFolder = app.chooseFolder({
    withPrompt: "Please select the SOURCE folder:"
    });


    var targetFolder = app.chooseFolder({
    withPrompt: "Please select the TARGET:"
    });

    console.log(result1, sourceFolder, targetFolder);


    var cmd = String(rsyncPath) + " --progress -av --exclude '.DS_Store*' --exclude .fseventsd --exclude '.Spotlight-V100*' --exclude '.TemporaryItems*' --exclude '.Trashes*' --exclude '.Trash*' --exclude 'Cache*' --exclude 'Saved Application State*' --exclude 'Logs*' --exclude 'DiagnosticReports*' --exclude '.journal*' --exclude '.journal_info_block*' --exclude 'lost+found*' --exclude 'Autosave Information' --exclude 'Library/Containers' --exclude 'Library/Group Containers' --exclude 'Library/Logs' '" + String(sourceFolder) + "\/' '" + String(targetFolder) + "'";


    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
    defaultAnswer: cmd,
    withIcon: "note",
  9. @glowinthedark glowinthedark revised this gist Mar 30, 2021. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
    // 2. Under menu File pick Export
    // 3. In the Export dialog select File Format = Application
    // 4. Save the app in /Applications
    // 2. Click the top-left dropdown which says 'AppleScript' and select 'JavaScript'
    // 3. Under menu File pick Export
    // 4. In the Export dialog select File Format = Application
    // 5. Save the app in /Applications

    var app = Application.currentApplication()
    app.includeStandardAdditions = true
  10. @glowinthedark glowinthedark revised this gist Mar 30, 2021. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
    // 2. Under menu File > Export select File Format = Application
    // 3. Save the app in /Applications
    // 2. Under menu File pick Export
    // 3. In the Export dialog select File Format = Application
    // 4. Save the app in /Applications

    var app = Application.currentApplication()
    app.includeStandardAdditions = true
  11. @glowinthedark glowinthedark revised this gist Mar 30, 2021. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ var targetFolder = app.chooseFolder({
    console.log(result1, sourceFolder, targetFolder);


    var cmd = String(rsyncPath) + " --progress -av --exclude '.DS_Store*' --exclude .fseventsd --exclude '.Spotlight-V100*' --exclude '.TemporaryItems*' --exclude '.Trashes*' --exclude '.Trash*' --exclude 'Cache*' --exclude 'Saved Application State*' --exclude 'Logs*' --exclude 'DiagnosticReports*' --exclude '.journal*' --exclude '.journal_info_block*' --exclude 'lost+found*' --exclude 'Autosave Information' --exclude 'Library/Containers' --exclude 'Library/Group Containers' --exclude 'Library/Logs' " + String(sourceFolder) + "\/ " + String(targetFolder);
    var cmd = String(rsyncPath) + " --progress -av --exclude '.DS_Store*' --exclude .fseventsd --exclude '.Spotlight-V100*' --exclude '.TemporaryItems*' --exclude '.Trashes*' --exclude '.Trash*' --exclude 'Cache*' --exclude 'Saved Application State*' --exclude 'Logs*' --exclude 'DiagnosticReports*' --exclude '.journal*' --exclude '.journal_info_block*' --exclude 'lost+found*' --exclude 'Autosave Information' --exclude 'Library/Containers' --exclude 'Library/Group Containers' --exclude 'Library/Logs' '" + String(sourceFolder) + "\/' '" + String(targetFolder) + "'";


    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
    @@ -55,5 +55,3 @@ app.displayAlert(cmd, {
    var terminal = Application('Terminal');
    terminal.activate();
    terminal.doScript(cmd);


  12. @glowinthedark glowinthedark created this gist Mar 30, 2021.
    59 changes: 59 additions & 0 deletions RsyncBackup.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    // 1. In MacOS Spotlight type 'Script Editor' and paste the code below
    // 2. Under menu File > Export select File Format = Application
    // 3. Save the app in /Applications

    var app = Application.currentApplication()
    app.includeStandardAdditions = true

    var result1 = app.displayAlert("Rsync Backup Wizard", {
    message: "Press Continue to select the rsync location and SOURCE/TARGET folders...",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue",
    cancelButton: "Cancel",
    withIcon: "caution"
    })

    var choices = ["/usr/bin/rsync", "/usr/local/bin/rsync"];

    var rsyncPath = app.chooseFromList(choices, {
    withPrompt: "Select the rsync binary path:",
    defaultItems: ["/usr/bin/rsync"]
    });

    var sourceFolder = app.chooseFolder({
    withPrompt: "Please select the SOURCE folder:"
    });


    var targetFolder = app.chooseFolder({
    withPrompt: "Please select the TARGET:"
    });

    console.log(result1, sourceFolder, targetFolder);


    var cmd = String(rsyncPath) + " --progress -av --exclude '.DS_Store*' --exclude .fseventsd --exclude '.Spotlight-V100*' --exclude '.TemporaryItems*' --exclude '.Trashes*' --exclude '.Trash*' --exclude 'Cache*' --exclude 'Saved Application State*' --exclude 'Logs*' --exclude 'DiagnosticReports*' --exclude '.journal*' --exclude '.journal_info_block*' --exclude 'lost+found*' --exclude 'Autosave Information' --exclude 'Library/Containers' --exclude 'Library/Group Containers' --exclude 'Library/Logs' " + String(sourceFolder) + "\/ " + String(targetFolder);


    var confirmationResponse = app.displayDialog("Press Continue to execute the following command in the terminal:", {
    defaultAnswer: cmd,
    withIcon: "note",
    buttons: ["Cancel", "Continue"],
    defaultButton: "Continue"
    })

    cmd = String(confirmationResponse.textReturned)

    app.displayAlert(cmd, {
    message: "The rsync command will be started in the terminal",
    buttons: ["Cancel", "🚀 Start Backup!"],
    defaultButton: "🚀 Start Backup!",
    cancelButton: "Cancel",
    withIcon: "caution"
    })

    var terminal = Application('Terminal');
    terminal.activate();
    terminal.doScript(cmd);