Skip to content

Instantly share code, notes, and snippets.

@itssoap
Created July 31, 2024 18:38
Show Gist options
  • Select an option

  • Save itssoap/e9272106166754058228940094ab151e to your computer and use it in GitHub Desktop.

Select an option

Save itssoap/e9272106166754058228940094ab151e to your computer and use it in GitHub Desktop.
Convenience script for Immich maintenance (In WSL, perform upgrade and DB backup)
#!/bin/bash
export mount_dir="/mnt/x/"
export path="immich-pg-backup/database-backup/"
if test -d ${mount_dir}${path}; then
printf "Backup PostgresDB? (y/n)? "
read -r answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "PostgresDB backup initiated."
sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | sudo tee "${mount_dir}${path}immich-database.sql_$(date +"%Y%m%d")"
echo "DB backup done."
fi
else
# the drive is a remote dir on Windows and immich runs on wsl
echo "Directory is being mounted..."
sudo mount -t drvfs X: ${mount_dir}
echo "Directory mounted."
if test -d ${mount_dir}${path}; then
echo "PostgresDB backup initiated."
sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | sudo tee "${mount_dir}${path}immich-database.sql_$(date +"%Y%m%d")"
echo "DB backup done."
else
echo "Backup Directory not found"
exit 1
fi
fi
printf "Upgrade immich as well? (y/n)? "
read -r answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
docker compose pull && sudo docker compose up -d
echo "Don't forget to upgrade the android app as well"
else
echo "Tschüss"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment