Created
June 19, 2026 23:52
-
-
Save JayCuthrell/369efb8a9d61665b0d319f78601be8a2 to your computer and use it in GitHub Desktop.
Rollback GoToSocial to the prior version
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # --- Configuration --- | |
| INSTALL_DIR="/gotosocial" | |
| BACKUP_DIR="$INSTALL_DIR/backups" | |
| GTS_DB_PATH="/var/lib/gotosocial/gts.db" | |
| # Ensure script is run as root | |
| if [[ "$EUID" -ne 0 ]]; then | |
| echo -e "\e[31m[ERROR]\e[0m Please run this script as root or using sudo." | |
| exit 1 | |
| fi | |
| # Move into the installation directory | |
| cd "$INSTALL_DIR" || exit 1 | |
| echo "--- GoToSocial Rollback Utility ---" | |
| # 1. Find the newest asset backup | |
| # ls -1t lists files sorted by time (newest first). head -n 1 grabs the top result. | |
| LATEST_ASSET_BACKUP=$(ls -1t "$BACKUP_DIR"/gts_assets_*.tar.gz 2>/dev/null | head -n 1) | |
| if [[ -z "$LATEST_ASSET_BACKUP" ]]; then | |
| echo -e "\e[31m[ERROR]\e[0m No asset backups found in $BACKUP_DIR." | |
| exit 1 | |
| fi | |
| # 2. Extract the timestamp from the filename to find the matching DB backup | |
| # This strips away the directory path and 'gts_assets_' prefix, leaving just the timestamp | |
| BASENAME=$(basename "$LATEST_ASSET_BACKUP") | |
| TIMESTAMP=${BASENAME#gts_assets_} | |
| TIMESTAMP=${TIMESTAMP%.tar.gz} | |
| LATEST_DB_BACKUP="$BACKUP_DIR/gts.db_$TIMESTAMP.db" | |
| if [[ ! -f "$LATEST_DB_BACKUP" ]]; then | |
| echo -e "\e[31m[ERROR]\e[0m Matching database backup not found for timestamp: $TIMESTAMP" | |
| echo -e "Expected to find: $LATEST_DB_BACKUP" | |
| exit 1 | |
| fi | |
| echo -e "Found the most recent backup set ($TIMESTAMP):" | |
| echo -e " Assets: \e[36m$LATEST_ASSET_BACKUP\e[0m" | |
| echo -e " DB: \e[36m$LATEST_DB_BACKUP\e[0m" | |
| # --- Argument Parsing for Safety --- | |
| if [[ "$1" != "--approved" ]]; then | |
| echo -e "\n\e[1m*** ROLLBACK PLAN: DRY RUN MODE ***\e[0m" | |
| echo -e "Run with \e[32m--approved\e[0m to execute this rollback and overwrite current files.\n" | |
| exit 0 | |
| fi | |
| # --- Execution Steps --- | |
| echo -e "\n\e[32m[EXECUTING]\e[0m Stopping GoToSocial service..." | |
| systemctl stop gotosocial | |
| echo -e "\e[32m[EXECUTING]\e[0m Restoring Database..." | |
| # Since the service is stopped, a standard 'cp' is safe to use for SQLite restoration | |
| cp "$LATEST_DB_BACKUP" "$GTS_DB_PATH" | |
| # Ensure the gotosocial user still owns the restored database file | |
| chown gotosocial:gotosocial "$GTS_DB_PATH" | |
| echo -e "\e[32m[EXECUTING]\e[0m Restoring web assets and binary..." | |
| tar -xzf "$LATEST_ASSET_BACKUP" | |
| echo -e "\e[32m[EXECUTING]\e[0m Fixing permissions..." | |
| chown root:root gotosocial | |
| chmod +x gotosocial | |
| chown -R gotosocial:gotosocial web | |
| echo -e "\e[32m[EXECUTING]\e[0m Restarting GoToSocial service..." | |
| systemctl start gotosocial | |
| echo -e "\n\e[32m✔ Rollback to $TIMESTAMP complete.\e[0m" | |
| systemctl status gotosocial --no-pager |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment