Skip to content

Instantly share code, notes, and snippets.

@hostmaster
Forked from jorijn/borgbackup.sh
Created May 3, 2020 20:14
Show Gist options
  • Select an option

  • Save hostmaster/bd4af5f1eb11b063b73e0e646c595d11 to your computer and use it in GitHub Desktop.

Select an option

Save hostmaster/bd4af5f1eb11b063b73e0e646c595d11 to your computer and use it in GitHub Desktop.

Revisions

  1. @jorijn jorijn revised this gist Jul 17, 2017. 1 changed file with 0 additions and 26 deletions.
    26 changes: 0 additions & 26 deletions borgbackup.sh
    Original file line number Diff line number Diff line change
    @@ -26,38 +26,12 @@ borg create \
    --exclude '/Users/*/.cache/*' \
    --exclude '/Users/*/.Trash/*' \
    --exclude '/Users/*/Library/Caches' \

    # this is where Apple stores local copies of your iCloud data. If you lose it due to a hard
    # drive failure, all of the data will be automatically downloaded again once you restore
    # your Mac and log in with iCloud.
    --exclude '/Users/*/Library/Mobile Documents' \

    # when you view an email attachment in Mail, it gets stored to this temporary location until
    # you save it to your drive or delete the message. Just as above with iCloud, if you lose
    # the contents of this folder, they’ll automatically re-download when you set your email account
    # back up after restoring.
    --exclude '/Users/*/Library/Containers/com.apple.mail/Data/Library/Mail Downloads' \

    # if your movies and TV show folders are filled exclusively with purchased iTunes content,
    # then you don’t have to worry about backing them up. These can be huge, multi-gigabyte files
    # that take up a lot of space, and you’ll always be able to download them again from Apple at any time.
    --exclude '/Users/*/Music/iTunes/iTunes Media/Movies' \
    --exclude '/Users/*/Music/iTunes/iTunes Media/TV Shows' \

    # services like Dropbox, SugarSync, and SkyDrive can be configured to store data on your local Mac.
    # Although it’s good to have at least one backup of the data stored on these services (in case their
    # data centers are ever destroyed), most users will be safe skipping these folders in their backup.
    # Once you’ve restored your Mac, simply reconnect to these services and re-download (or re-sync) your data.
    --exclude '/Users/*/Dropbox' \
    --exclude '/Users/*/Google Drive' \

    # users who run virtualization software like Parallels Desktop or VMware Fusion likely have at
    # least one huge virtual machine file on their Mac. If you use a VM for actual work, such as
    # running Windows-only accounting software, then you’ll definitely want to back these files up.
    # But if you only use them for testing, and the machines hold no crucial data, then you can safely
    # exclude them if you choose. You’ll have to go through the process of recreating the machines and
    # reinstalling your virtual OS, but it might be worth it for some users to save 30 or 40 GB on their
    # backup drive.
    --exclude '/Users/*/VirtualBox VMs' \
    \
    ::'{hostname}-{now}' \
  2. @jorijn jorijn created this gist Jul 17, 2017.
    102 changes: 102 additions & 0 deletions borgbackup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,102 @@
    #!/bin/bash

    # Setting this, so the repo does not need to be given on the commandline:
    export BORG_REPO='*******'

    # Setting this, so you won't be asked for your repository passphrase:
    export BORG_PASSPHRASE='*******'

    # some helpers and error handling:
    function info () { echo -e "\n"`date` $@"\n" >&2; }
    trap "echo `date` Backup interrupted >&2; exit 2" SIGINT SIGTERM

    info "Starting backup"

    # Backup the most important directories into an archive named after
    # the machine this script is currently running on:

    borg create \
    --verbose \
    --filter AME \
    --list \
    --stats \
    --show-rc \
    --compression lz4 \
    --exclude-caches \
    --exclude '/Users/*/.cache/*' \
    --exclude '/Users/*/.Trash/*' \
    --exclude '/Users/*/Library/Caches' \

    # this is where Apple stores local copies of your iCloud data. If you lose it due to a hard
    # drive failure, all of the data will be automatically downloaded again once you restore
    # your Mac and log in with iCloud.
    --exclude '/Users/*/Library/Mobile Documents' \

    # when you view an email attachment in Mail, it gets stored to this temporary location until
    # you save it to your drive or delete the message. Just as above with iCloud, if you lose
    # the contents of this folder, they’ll automatically re-download when you set your email account
    # back up after restoring.
    --exclude '/Users/*/Library/Containers/com.apple.mail/Data/Library/Mail Downloads' \

    # if your movies and TV show folders are filled exclusively with purchased iTunes content,
    # then you don’t have to worry about backing them up. These can be huge, multi-gigabyte files
    # that take up a lot of space, and you’ll always be able to download them again from Apple at any time.
    --exclude '/Users/*/Music/iTunes/iTunes Media/Movies' \
    --exclude '/Users/*/Music/iTunes/iTunes Media/TV Shows' \

    # services like Dropbox, SugarSync, and SkyDrive can be configured to store data on your local Mac.
    # Although it’s good to have at least one backup of the data stored on these services (in case their
    # data centers are ever destroyed), most users will be safe skipping these folders in their backup.
    # Once you’ve restored your Mac, simply reconnect to these services and re-download (or re-sync) your data.
    --exclude '/Users/*/Dropbox' \
    --exclude '/Users/*/Google Drive' \

    # users who run virtualization software like Parallels Desktop or VMware Fusion likely have at
    # least one huge virtual machine file on their Mac. If you use a VM for actual work, such as
    # running Windows-only accounting software, then you’ll definitely want to back these files up.
    # But if you only use them for testing, and the machines hold no crucial data, then you can safely
    # exclude them if you choose. You’ll have to go through the process of recreating the machines and
    # reinstalling your virtual OS, but it might be worth it for some users to save 30 or 40 GB on their
    # backup drive.
    --exclude '/Users/*/VirtualBox VMs' \
    \
    ::'{hostname}-{now}' \
    /Users \
    /Library \
    /Applications \
    /usr/local # homebrew

    backup_exit=$?

    info "Pruning repository"

    # Use the `prune` subcommand to maintain 24 hourly, 7 daily, 4 weekly and 6 monthly
    # archives of THIS machine. The '{hostname}-' prefix is very important to
    # limit prune's operation to this machine's archives and not apply to
    # other machines' archives also:

    borg prune \
    --list \
    --prefix '{hostname}-' \
    --show-rc \
    --stats \
    --keep-hourly 24 \
    --keep-daily 7 \
    --keep-weekly 4 \
    --keep-monthly 6 \

    prune_exit=$?

    global_exit=$(( ${backup_exit} > ${prune_exit} ? ${backup_exit} : ${prune_exit} ))

    if [ ${global_exit} -eq 1 ];
    then
    info "Backup and/or Prune finished with a warning"
    fi

    if [ ${global_exit} -gt 1 ];
    then
    info "Backup and/or Prune finished with an error"
    fi

    exit ${global_exit}