Borgbackup: Difference between revisions

 
(12 intermediate revisions by the same user not shown)
Line 17: Line 17:
# Create a repo without encryption
# Create a repo without encryption
borg init --encryption=none ./testrepo
borg init --encryption=none ./testrepo
# If you want encryption
# If you want encryption
#borg init --encryption=repokey ./testrepo
borg init --encryption=repokey ./testrepo
</pre>
</pre>


Line 61: 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">
REPOSITORY="ssh://t440s-server-local:~/Backups/my_backup"
#!/bin/bash
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 92: Line 100:
)
)
BORG_EXEC="borg"
BORG_EXEC="borg"
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
LOCKFILE=/tmp/backup_server.lockfile
LOGFILE=/home/david/Documents/server-backup-scripts/my_backup.log
exec {lock_fd}>$LOCKFILE || exit 1
flock -n "$lock_fd" || {
  echo "Another instance is running" >&2
  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]