Created
August 25, 2023 01:30
-
-
Save noskla/deeaf9ba365f5caa1f3407697a9806b9 to your computer and use it in GitHub Desktop.
Backup script for Docker release of Akkoma (akkoma.social)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
date_today=$(date +"%d_%m_%Y") | |
akkoma_workdir="/home/$USER/akkoma" | |
akkoma_db_img_name="akkoma-db" | |
backup_temp_dir="/home/$USER/backup_tmp" | |
backup_zip_dir="/home/$USER/backups" | |
# check working directory | |
echo "Verifying working directory..." | |
if [[ $PWD != $akkoma_workdir ]]; then | |
cd $akkoma_workdir | |
fi | |
echo "Stopping akkoma..." | |
# stop akkoma service | |
docker compose stop akkoma | |
echo "Creating a temp directory..." | |
# create a temp backup directory | |
mkdir -p $backup_temp_dir | |
echo "Getting a database docker container ID..." | |
# get id of the db container | |
akkoma_db_id=$(docker ps -aqf "ancestor=$akkoma_db_img_name") | |
echo "Comitting a database dump...(it may take a while)" | |
# create a backup dump of the db | |
docker exec $akkoma_db_id pg_dump -d akkoma --format=custom > "$backup_temp_dir/backup.pgdump" | |
echo "Copying configuration data..." | |
# copy config data | |
cp -r "$akkoma_workdir/config" "$backup_temp_dir/config" | |
echo "Copying file uploads..." | |
# copy uploads data | |
cp -r "$akkoma_workdir/uploads" "$backup_temp_dir/uploads" | |
echo "Starting akkoma..." | |
# (re)start akkoma service | |
docker compose start akkoma | |
echo "Creating zip directory..." | |
# create a backup directory | |
mkdir -p $backup_zip_dir | |
echo "Compressing backup data..." | |
# zip up the backup data | |
zip_filename="$backup_zip_dir/akkoma_backup-$date_today.7z" | |
7z a $zip_filename "$backup_temp_dir/*" | |
echo "Cleanup..." | |
# cleanup / del the temp dir | |
rm -r $backup_temp_dir | |
echo -e "Back-up ready! $zip_filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment