Borgbackup: Difference between revisions

 
(8 intermediate revisions by the same user not shown)
Line 62: Line 62:
* You should extract to an empty folder since borg does not delete existing files in the target folder.
* You should extract to an empty folder since borg does not delete existing files in the target folder.


==Example Scripts==
==Scheduling==
 
===borgmatic===
See [https://torsion.org/borgmatic/ https://torsion.org/borgmatic/]
 
===Bash Script===
Below is a bash script you can call from cron or systemd.
{{hidden | backup.sh |
{{hidden | backup.sh |
<pre>
<syntaxhighlight lang="bash">
#!/bin/bash
REPOSITORY="my_server:~/Backups/my_backup"
REPOSITORY="my_server:~/Backups/my_backup"
ARCHIVE_NAME="{hostname}-{utcnow}"
ARCHIVE_NAME="{hostname}-{utcnow}"
SOURCE_DIR="./"
SOURCE_DIR="/home/david/"
BACKUP_DIRS=(
BACKUP_DIRS=(
   "."
   "."
Line 96: Line 103:
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
LOCKFILE=/tmp/backup_server.lockfile
LOCKFILE=/tmp/backup_server.lockfile
LOGFILE=/home/david/Documents/server-backup-scripts/my_backup.log


exec {lock_fd}>$LOCKFILE || exit 1
exec {lock_fd}>$LOCKFILE || exit 1
Line 102: Line 110:
   exit 1
   exit 1
}
}
function send_fail_email {
  {
    echo From: [email protected]
    echo To: [email protected]
    echo Subject: my_backup failed
    echo
    echo my_backup failed
  } | /usr/lib/sendmail -t
  exit
}
if [ -d "${SOURCE_DIR}" ]
if [ -d "${SOURCE_DIR}" ]
then
then
  # shellcheck disable=SC2015
   cd "${SOURCE_DIR}" && \
   cd "${SOURCE_DIR}" && \
  $BORG_EXEC create "${BORG_CREATE_FLAGS[@]}" "${EXCLUSIONS[@]}" "${REPOSITORY}"::"${ARCHIVE_NAME}" "${BACKUP_DIRS[@]}" && \
    $BORG_EXEC create "${BORG_CREATE_FLAGS[@]}" "${EXCLUSIONS[@]}" "${REPOSITORY}"::"${ARCHIVE_NAME}" "${BACKUP_DIRS[@]}" 2>&1 | tee "$LOGFILE" &&
  $BORG_EXEC prune "${BORG_PRUNE_FLAGS[@]}" "${REPOSITORY}"
    $BORG_EXEC prune "${BORG_PRUNE_FLAGS[@]}" "${REPOSITORY}" | tee -a "$LOGFILE" ||
    send_fail_email
fi
fi
</pre>
</syntaxhighlight>
}}
}}
==Borg vs Restic==
Restic is a very similar piece of software which supports backing up to S3-compatible (e.g. S3, Minio, Backblaze B2) storage.
==Hosted Services==
See https://www.borgbackup.org/support/commercial.html


==Resources==
==Resources==
* [https://practical-admin.com/blog/backups-using-borg/ practical-admin backups using borg]
* [https://practical-admin.com/blog/backups-using-borg/ practical-admin backups using borg]