Skip to content

Instantly share code, notes, and snippets.

@mmomjian
Last active July 21, 2024 19:41
Show Gist options
  • Save mmomjian/58ff9a6de3af403a3be0b1bc74271976 to your computer and use it in GitHub Desktop.
Save mmomjian/58ff9a6de3af403a3be0b1bc74271976 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o nounset
set -o pipefail
# for first time init, run `./command_name init`
# edit these variables
BACKBLAZE_BUCKET='bucketname'
BACKBLAZE_URL='bburl.com'
ImmichPaths=('/path1' '/path2')
export AWS_ACCESS_KEY_ID='access_key'
export AWS_SECRET_ACCESS_KEY='secret_key'
# do not edit below this line
export RESTIC_REPOSITORY=s3:"$BACKBLAZE_URL/$BACKBLAZE_BUCKET"
main () {
[[ $(id -u) == 0 ]] || { echo 'must run as root'; return 50; }
if [[ $# != 0 ]]
then restic "$@" || { echo 'ERROR in restic command'; return 40; }
return
fi
local Exit=0
local -r PgDump='/pg_dump_immich.sql'
docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres > "$PgDump"
[[ $? == 0 ]] || { echo 'failure dumping postgres'; return 51; }
restic backup "${ImmichPaths[@]}" "$PgDump"
[[ $? == 0 ]] || { echo 'error backing up restic command'; return 52; }
rm "$PgDump" || { echo 'error removing PG backup temp file'; return 53; }
return "$Exit"; }
main
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment