How do I automate borg backup?












1















Background



I would like to use Borg Backup as a backup solution for my Ubuntu server. They offer a very convenient sh script that they say you can just run as a cron job, but it is not working for me.



Problem



How do I automate borg backup? If the best way is to use cron, then what is wrong with my impementation?



Data



Root's Crontab:



# 5 2 * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null      # Back up the root partition daily (2:05a)
* * * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null # Test the script


borgBackup_run.sh:



Modified from the original to be very bare-bones:



#!/bin/sh

echo 'Starting backup now...' >>
/home/***/Logs/borgBackup_create.log

#/usr/bin/borg create --verbose --filter AME --list --stats --show-rc --compression lz4 --exclude-caches --one-file-system --exclude-from ~/Scripts/borgBackup_exclude.txt /mnt/RootBackup/borg::'{hostname}-{now:%Y-%m-%d}' /
/usr/bin/borg create /mnt/RootBackup/borg::cronTest /home/***/Logs/ # Backup a small folder as a test

echo 'Done.' >> /home/***/Logs/borgBackup_create.log


"ls -l ~/Scripts/borgBackup_run.sh"



-rwxr-xr-x 1 root root 455 Sep 27 12:34 Scripts/borgBackup_run.sh


Notes:



When borgBackup_run.sh is run from the commandline, as: sudo Scripts/borgBackup_run.sh, the script works perfectly, creating a new archive in /mnt/RootBackup/borg.



Additionally, after each minute (when the cronjob runs), the .log file at /home/***/Logs/borgBackup_create.log shows both Starting backup now... and Done., indicating that the script has run all the way through, but borg did not work for some reason.



I have tried removing sh from the crontab file, using bash instead, and changing the interobang to #!/bin/bash instead of #!/bin/sh. I have also tried wrapping the line /user/bin/borg create ... line in borgBackup_run.sh in bash -c "...".



Any help would be greatly appreciated!










share|improve this question


















  • 2





    And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

    – grawity
    Sep 27 '18 at 17:58






  • 2





    Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

    – Tyson
    Sep 27 '18 at 18:12











  • Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

    – sgbrown
    Sep 27 '18 at 18:34











  • @Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

    – sgbrown
    Sep 27 '18 at 18:35











  • Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

    – Tyson
    Sep 28 '18 at 12:49
















1















Background



I would like to use Borg Backup as a backup solution for my Ubuntu server. They offer a very convenient sh script that they say you can just run as a cron job, but it is not working for me.



Problem



How do I automate borg backup? If the best way is to use cron, then what is wrong with my impementation?



Data



Root's Crontab:



# 5 2 * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null      # Back up the root partition daily (2:05a)
* * * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null # Test the script


borgBackup_run.sh:



Modified from the original to be very bare-bones:



#!/bin/sh

echo 'Starting backup now...' >>
/home/***/Logs/borgBackup_create.log

#/usr/bin/borg create --verbose --filter AME --list --stats --show-rc --compression lz4 --exclude-caches --one-file-system --exclude-from ~/Scripts/borgBackup_exclude.txt /mnt/RootBackup/borg::'{hostname}-{now:%Y-%m-%d}' /
/usr/bin/borg create /mnt/RootBackup/borg::cronTest /home/***/Logs/ # Backup a small folder as a test

echo 'Done.' >> /home/***/Logs/borgBackup_create.log


"ls -l ~/Scripts/borgBackup_run.sh"



-rwxr-xr-x 1 root root 455 Sep 27 12:34 Scripts/borgBackup_run.sh


Notes:



When borgBackup_run.sh is run from the commandline, as: sudo Scripts/borgBackup_run.sh, the script works perfectly, creating a new archive in /mnt/RootBackup/borg.



Additionally, after each minute (when the cronjob runs), the .log file at /home/***/Logs/borgBackup_create.log shows both Starting backup now... and Done., indicating that the script has run all the way through, but borg did not work for some reason.



I have tried removing sh from the crontab file, using bash instead, and changing the interobang to #!/bin/bash instead of #!/bin/sh. I have also tried wrapping the line /user/bin/borg create ... line in borgBackup_run.sh in bash -c "...".



Any help would be greatly appreciated!










share|improve this question


















  • 2





    And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

    – grawity
    Sep 27 '18 at 17:58






  • 2





    Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

    – Tyson
    Sep 27 '18 at 18:12











  • Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

    – sgbrown
    Sep 27 '18 at 18:34











  • @Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

    – sgbrown
    Sep 27 '18 at 18:35











  • Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

    – Tyson
    Sep 28 '18 at 12:49














1












1








1








Background



I would like to use Borg Backup as a backup solution for my Ubuntu server. They offer a very convenient sh script that they say you can just run as a cron job, but it is not working for me.



Problem



How do I automate borg backup? If the best way is to use cron, then what is wrong with my impementation?



Data



Root's Crontab:



# 5 2 * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null      # Back up the root partition daily (2:05a)
* * * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null # Test the script


borgBackup_run.sh:



Modified from the original to be very bare-bones:



#!/bin/sh

echo 'Starting backup now...' >>
/home/***/Logs/borgBackup_create.log

#/usr/bin/borg create --verbose --filter AME --list --stats --show-rc --compression lz4 --exclude-caches --one-file-system --exclude-from ~/Scripts/borgBackup_exclude.txt /mnt/RootBackup/borg::'{hostname}-{now:%Y-%m-%d}' /
/usr/bin/borg create /mnt/RootBackup/borg::cronTest /home/***/Logs/ # Backup a small folder as a test

echo 'Done.' >> /home/***/Logs/borgBackup_create.log


"ls -l ~/Scripts/borgBackup_run.sh"



-rwxr-xr-x 1 root root 455 Sep 27 12:34 Scripts/borgBackup_run.sh


Notes:



When borgBackup_run.sh is run from the commandline, as: sudo Scripts/borgBackup_run.sh, the script works perfectly, creating a new archive in /mnt/RootBackup/borg.



Additionally, after each minute (when the cronjob runs), the .log file at /home/***/Logs/borgBackup_create.log shows both Starting backup now... and Done., indicating that the script has run all the way through, but borg did not work for some reason.



I have tried removing sh from the crontab file, using bash instead, and changing the interobang to #!/bin/bash instead of #!/bin/sh. I have also tried wrapping the line /user/bin/borg create ... line in borgBackup_run.sh in bash -c "...".



Any help would be greatly appreciated!










share|improve this question














Background



I would like to use Borg Backup as a backup solution for my Ubuntu server. They offer a very convenient sh script that they say you can just run as a cron job, but it is not working for me.



Problem



How do I automate borg backup? If the best way is to use cron, then what is wrong with my impementation?



Data



Root's Crontab:



# 5 2 * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null      # Back up the root partition daily (2:05a)
* * * * * sh /home/***/Scripts/borgBackup_run.sh >/dev/null # Test the script


borgBackup_run.sh:



Modified from the original to be very bare-bones:



#!/bin/sh

echo 'Starting backup now...' >>
/home/***/Logs/borgBackup_create.log

#/usr/bin/borg create --verbose --filter AME --list --stats --show-rc --compression lz4 --exclude-caches --one-file-system --exclude-from ~/Scripts/borgBackup_exclude.txt /mnt/RootBackup/borg::'{hostname}-{now:%Y-%m-%d}' /
/usr/bin/borg create /mnt/RootBackup/borg::cronTest /home/***/Logs/ # Backup a small folder as a test

echo 'Done.' >> /home/***/Logs/borgBackup_create.log


"ls -l ~/Scripts/borgBackup_run.sh"



-rwxr-xr-x 1 root root 455 Sep 27 12:34 Scripts/borgBackup_run.sh


Notes:



When borgBackup_run.sh is run from the commandline, as: sudo Scripts/borgBackup_run.sh, the script works perfectly, creating a new archive in /mnt/RootBackup/borg.



Additionally, after each minute (when the cronjob runs), the .log file at /home/***/Logs/borgBackup_create.log shows both Starting backup now... and Done., indicating that the script has run all the way through, but borg did not work for some reason.



I have tried removing sh from the crontab file, using bash instead, and changing the interobang to #!/bin/bash instead of #!/bin/sh. I have also tried wrapping the line /user/bin/borg create ... line in borgBackup_run.sh in bash -c "...".



Any help would be greatly appreciated!







linux bash backup shell cron






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 27 '18 at 17:49









sgbrownsgbrown

164




164








  • 2





    And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

    – grawity
    Sep 27 '18 at 17:58






  • 2





    Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

    – Tyson
    Sep 27 '18 at 18:12











  • Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

    – sgbrown
    Sep 27 '18 at 18:34











  • @Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

    – sgbrown
    Sep 27 '18 at 18:35











  • Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

    – Tyson
    Sep 28 '18 at 12:49














  • 2





    And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

    – grawity
    Sep 27 '18 at 17:58






  • 2





    Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

    – Tyson
    Sep 27 '18 at 18:12











  • Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

    – sgbrown
    Sep 27 '18 at 18:34











  • @Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

    – sgbrown
    Sep 27 '18 at 18:35











  • Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

    – Tyson
    Sep 28 '18 at 12:49








2




2





And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

– grawity
Sep 27 '18 at 17:58





And what does borg itself say? I see you've tried options like --verbose and --stats. Surely the stdout/stderr goes somewhere; either to root's email inbox, or to the local /var/spool/mail/root mailbox, or at least to syslog.

– grawity
Sep 27 '18 at 17:58




2




2





Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

– Tyson
Sep 27 '18 at 18:12





Change the end of the crontab entry from ‘>/dev/null’ to ‘>/path/to/somewhere/cron_output 2>&1’ and see if you catch anything meaningful in that file. Also the /usr/bin/borg..... line of the script doesn’t seem to be re-directing output to your .log file. Currently output would be sent to /dev/null

– Tyson
Sep 27 '18 at 18:12













Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

– sgbrown
Sep 27 '18 at 18:34





Thank you for both of your comments! @grawity: I previously had the stdout of borg directed to that same borgBackup_create.log file, however I will try redirecting strerr, as well.

– sgbrown
Sep 27 '18 at 18:34













@Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

– sgbrown
Sep 27 '18 at 18:35





@Tyson: I had directed the stdout and stderr of the script in the cron file to a log previously. It creates the .log file, but does not add any content.

– sgbrown
Sep 27 '18 at 18:35













Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

– Tyson
Sep 28 '18 at 12:49





Just suggesting what I’ve done in the past to solve cron issues. In one case a typo didn’t become obvious until I quit trashing stdout and errout at the cron level.

– Tyson
Sep 28 '18 at 12:49










2 Answers
2






active

oldest

votes


















1














I figured out the problem, and am posting the solution in case anyone in the future has a similar problem.



I set up my repository to be unencrypted, which caused borg to attempt to run interactively (asking stdout if backing up to an unencrypted repository is ok). To make borg run non-interactively, I had to export an "automatic answerer" in borgBackup_run.sh, before the call to borg create .... The new line in the script looks like:



export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes


The name of this variable was found in the man page for borg. A number of other "automatic answerers" can also be found in the man page, to ensure that borg runs non-interactively in a script.






share|improve this answer































    1














    I just finished creating a similar cron script. Included is a sync of the borg backup files to BackBlaze's cloud storage platform (similar to amazon s3, but cheaper). Hopefully this will be useful to someone else looking for automating borg with a low-cost offsite backup!



    #!/bin/sh

    echo "Starting backup for `date`n"

    # setup script variables
    export BORG_PASSPHRASE="secret-passphrase-here!"
    export BORG_REPO="/path/to/repo"
    export BACKUP_TARGETS="/path1/to/backup /path2/to/backup"
    export BACKUP_NAME="backup-and-remote-folder-name"

    # create borg backup archive
    cmd="borg create ::`date +%Y%m%d`-$BACKUP_NAME $BACKUP_TARGETS --stats"
    $cmd

    # prune old archives to keep disk space in check
    borg prune -v --list --keep-daily=3 --keep-weekly=2

    # sync backups to offsite storage
    b2 authorize-account accountID applictionKey
    b2 sync --delete --replaceNewer $BORG_REPO b2://bucket-name/$BACKUP_NAME

    # all done!
    echo "Backup complete at `date`n";


    Currently running once a day with the following crontab



    0 11 * * * /path/to/script/backup.sh >> /path/to/logfile/backup.log 2>&1


    Requires a BackBlaze account and their CLI tool CLI installati






    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1361971%2fhow-do-i-automate-borg-backup%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I figured out the problem, and am posting the solution in case anyone in the future has a similar problem.



      I set up my repository to be unencrypted, which caused borg to attempt to run interactively (asking stdout if backing up to an unencrypted repository is ok). To make borg run non-interactively, I had to export an "automatic answerer" in borgBackup_run.sh, before the call to borg create .... The new line in the script looks like:



      export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes


      The name of this variable was found in the man page for borg. A number of other "automatic answerers" can also be found in the man page, to ensure that borg runs non-interactively in a script.






      share|improve this answer




























        1














        I figured out the problem, and am posting the solution in case anyone in the future has a similar problem.



        I set up my repository to be unencrypted, which caused borg to attempt to run interactively (asking stdout if backing up to an unencrypted repository is ok). To make borg run non-interactively, I had to export an "automatic answerer" in borgBackup_run.sh, before the call to borg create .... The new line in the script looks like:



        export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes


        The name of this variable was found in the man page for borg. A number of other "automatic answerers" can also be found in the man page, to ensure that borg runs non-interactively in a script.






        share|improve this answer


























          1












          1








          1







          I figured out the problem, and am posting the solution in case anyone in the future has a similar problem.



          I set up my repository to be unencrypted, which caused borg to attempt to run interactively (asking stdout if backing up to an unencrypted repository is ok). To make borg run non-interactively, I had to export an "automatic answerer" in borgBackup_run.sh, before the call to borg create .... The new line in the script looks like:



          export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes


          The name of this variable was found in the man page for borg. A number of other "automatic answerers" can also be found in the man page, to ensure that borg runs non-interactively in a script.






          share|improve this answer













          I figured out the problem, and am posting the solution in case anyone in the future has a similar problem.



          I set up my repository to be unencrypted, which caused borg to attempt to run interactively (asking stdout if backing up to an unencrypted repository is ok). To make borg run non-interactively, I had to export an "automatic answerer" in borgBackup_run.sh, before the call to borg create .... The new line in the script looks like:



          export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes


          The name of this variable was found in the man page for borg. A number of other "automatic answerers" can also be found in the man page, to ensure that borg runs non-interactively in a script.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 28 '18 at 22:48









          sgbrownsgbrown

          164




          164

























              1














              I just finished creating a similar cron script. Included is a sync of the borg backup files to BackBlaze's cloud storage platform (similar to amazon s3, but cheaper). Hopefully this will be useful to someone else looking for automating borg with a low-cost offsite backup!



              #!/bin/sh

              echo "Starting backup for `date`n"

              # setup script variables
              export BORG_PASSPHRASE="secret-passphrase-here!"
              export BORG_REPO="/path/to/repo"
              export BACKUP_TARGETS="/path1/to/backup /path2/to/backup"
              export BACKUP_NAME="backup-and-remote-folder-name"

              # create borg backup archive
              cmd="borg create ::`date +%Y%m%d`-$BACKUP_NAME $BACKUP_TARGETS --stats"
              $cmd

              # prune old archives to keep disk space in check
              borg prune -v --list --keep-daily=3 --keep-weekly=2

              # sync backups to offsite storage
              b2 authorize-account accountID applictionKey
              b2 sync --delete --replaceNewer $BORG_REPO b2://bucket-name/$BACKUP_NAME

              # all done!
              echo "Backup complete at `date`n";


              Currently running once a day with the following crontab



              0 11 * * * /path/to/script/backup.sh >> /path/to/logfile/backup.log 2>&1


              Requires a BackBlaze account and their CLI tool CLI installati






              share|improve this answer






























                1














                I just finished creating a similar cron script. Included is a sync of the borg backup files to BackBlaze's cloud storage platform (similar to amazon s3, but cheaper). Hopefully this will be useful to someone else looking for automating borg with a low-cost offsite backup!



                #!/bin/sh

                echo "Starting backup for `date`n"

                # setup script variables
                export BORG_PASSPHRASE="secret-passphrase-here!"
                export BORG_REPO="/path/to/repo"
                export BACKUP_TARGETS="/path1/to/backup /path2/to/backup"
                export BACKUP_NAME="backup-and-remote-folder-name"

                # create borg backup archive
                cmd="borg create ::`date +%Y%m%d`-$BACKUP_NAME $BACKUP_TARGETS --stats"
                $cmd

                # prune old archives to keep disk space in check
                borg prune -v --list --keep-daily=3 --keep-weekly=2

                # sync backups to offsite storage
                b2 authorize-account accountID applictionKey
                b2 sync --delete --replaceNewer $BORG_REPO b2://bucket-name/$BACKUP_NAME

                # all done!
                echo "Backup complete at `date`n";


                Currently running once a day with the following crontab



                0 11 * * * /path/to/script/backup.sh >> /path/to/logfile/backup.log 2>&1


                Requires a BackBlaze account and their CLI tool CLI installati






                share|improve this answer




























                  1












                  1








                  1







                  I just finished creating a similar cron script. Included is a sync of the borg backup files to BackBlaze's cloud storage platform (similar to amazon s3, but cheaper). Hopefully this will be useful to someone else looking for automating borg with a low-cost offsite backup!



                  #!/bin/sh

                  echo "Starting backup for `date`n"

                  # setup script variables
                  export BORG_PASSPHRASE="secret-passphrase-here!"
                  export BORG_REPO="/path/to/repo"
                  export BACKUP_TARGETS="/path1/to/backup /path2/to/backup"
                  export BACKUP_NAME="backup-and-remote-folder-name"

                  # create borg backup archive
                  cmd="borg create ::`date +%Y%m%d`-$BACKUP_NAME $BACKUP_TARGETS --stats"
                  $cmd

                  # prune old archives to keep disk space in check
                  borg prune -v --list --keep-daily=3 --keep-weekly=2

                  # sync backups to offsite storage
                  b2 authorize-account accountID applictionKey
                  b2 sync --delete --replaceNewer $BORG_REPO b2://bucket-name/$BACKUP_NAME

                  # all done!
                  echo "Backup complete at `date`n";


                  Currently running once a day with the following crontab



                  0 11 * * * /path/to/script/backup.sh >> /path/to/logfile/backup.log 2>&1


                  Requires a BackBlaze account and their CLI tool CLI installati






                  share|improve this answer















                  I just finished creating a similar cron script. Included is a sync of the borg backup files to BackBlaze's cloud storage platform (similar to amazon s3, but cheaper). Hopefully this will be useful to someone else looking for automating borg with a low-cost offsite backup!



                  #!/bin/sh

                  echo "Starting backup for `date`n"

                  # setup script variables
                  export BORG_PASSPHRASE="secret-passphrase-here!"
                  export BORG_REPO="/path/to/repo"
                  export BACKUP_TARGETS="/path1/to/backup /path2/to/backup"
                  export BACKUP_NAME="backup-and-remote-folder-name"

                  # create borg backup archive
                  cmd="borg create ::`date +%Y%m%d`-$BACKUP_NAME $BACKUP_TARGETS --stats"
                  $cmd

                  # prune old archives to keep disk space in check
                  borg prune -v --list --keep-daily=3 --keep-weekly=2

                  # sync backups to offsite storage
                  b2 authorize-account accountID applictionKey
                  b2 sync --delete --replaceNewer $BORG_REPO b2://bucket-name/$BACKUP_NAME

                  # all done!
                  echo "Backup complete at `date`n";


                  Currently running once a day with the following crontab



                  0 11 * * * /path/to/script/backup.sh >> /path/to/logfile/backup.log 2>&1


                  Requires a BackBlaze account and their CLI tool CLI installati







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 30 '18 at 4:06

























                  answered Dec 29 '18 at 3:57









                  GlenGlen

                  1112




                  1112






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1361971%2fhow-do-i-automate-borg-backup%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Plaza Victoria

                      In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                      How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...