Skip to content

Instantly share code, notes, and snippets.

@bergercookie
Last active July 1, 2024 07:32
Show Gist options
  • Save bergercookie/bd5ef60c221c1c19f33caff672d5a8c4 to your computer and use it in GitHub Desktop.
Save bergercookie/bd5ef60c221c1c19f33caff672d5a8c4 to your computer and use it in GitHub Desktop.
Mealie automatic backups script
#!/usr/bin/env bash
# This script is used to backup mealie data from a mealie server instance to a
# local directory.
#
# It will request a backup to be created in the server and it will then request
# its download.
#
# Usage: do-mealie-backup.sh [server_addr] [backup_dir] [username] [password]
#
# server_addr: The address:port of the mealie server instance.
# backup_dir: The directory where the backup will be saved.
# username: The username to authenticate with the mealie server.
# password: The password to authenticate with the mealie server.
set -ex
server_addr="${1:-$SERVER_ADDR}"
backup_dir=${2:-$BACKUP_DIR}
username="${3:-$USERNAME}"
password="${4:-$PASSWORD}"
access_token=$(
curl --fail --silent -X 'POST' \
"$server_addr/api/auth/token" \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d "grant_type=&username=$username&password=$password&remember_me=false&scope=&client_id=&client_secret=" | jq -r '.access_token'
)
curl --fail -X 'POST' \
"$server_addr/api/admin/backups" \
-H 'accept: application/json' \
-H "Authorization: Bearer $access_token" \
-d ''
backup_name=$(
curl --fail -X 'GET' \
"$server_addr/api/admin/backups" \
-H 'accept: application/json' \
-H "Authorization: Bearer $access_token" | jq -r '.imports[0].name'
)
download_token=$(
curl -X 'GET' \
"$server_addr/api/admin/backups/$backup_name" \
-H 'accept: application/json' \
-H "Authorization: Bearer $access_token" | jq -r '.fileToken'
)
curl -X 'GET' \
"$server_addr/api/utils/download?token=$download_token" \
-H 'accept: application/json' \
-H "Authorization: Bearer $access_token" \
--output $backup_dir/$backup_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment