#!/bin/bash # The remote restore process # ~~~~~~~~~~~~~~~~~~~~~~~~~~ # # Restore from the hourly backup on the server clear # Stop the running PostgreSQL service echo -e "\e[1;33mStop the running PostgreSQL service...\e[0m" sudo systemctl stop postgresql.service echo -e "\e[32mDone\e[0m" echo "" # Current PostgreSQL status echo -e "\e[1;33mCurrent PostgreSQL status...\e[0m" sudo systemctl status postgresql echo -e "\e[32mDone\e[0m" echo "" # chown the existing PostgreSQL installation echo -e "\e[1;33mchown the existing PostgreSQL installation...\e[0m" sudo chown -R foo:foo /var/lib/postgresql/15/main/ echo -e "\e[32mDone\e[0m" echo "" # Remove the existing PostgreSQL files echo -e "\e[1;33mRemove the existing PostgreSQL files...\e[0m" sudo rm -fr /var/lib/postgresql/15/main/* echo -e "\e[32mDone\e[0m" echo "" # Copy the latest backup to the PostgreSQL target location echo -e "\e[1;33mCopy the latest backup to the PostgreSQL target location...\e[0m" sudo cp -R /home/foo/Backups/calckey/postgresql/* /var/lib/postgresql/15/main/ echo -e "\e[32mDone\e[0m" echo "" # Make the PostgreSQL user take ownership of the target location echo -e "\e[1;33mMake the PostgreSQL user take ownership of the target location...\e[0m" sudo chown -R postgres:postgres /var/lib/postgresql/15/main/ echo -e "\e[32mDone\e[0m" echo "" # Start the PostgreSQL service echo -e "\e[1;33mStart the PostgreSQL service...\e[0m" sudo systemctl start postgresql.service echo -e "\e[32mDone\e[0m" echo "" # Current PostgreSQL status echo -e "\e[1;33mCurrent PostgreSQL status...\e[0m" sudo systemctl status postgresql echo -e "\e[32mDone\e[0m" echo "" # Restore the calckey /files/ directory echo -e "\e[1;33mRestore the calckey /files/ directory...\e[0m" sudo cp /home/foo/Backups/calckey/files/* /home/calckey/calckey/files echo -e "\e[32mDone\e[0m" echo ""