(wip) finish upgrade steps, work on backup'
This commit is contained in:
parent
a805c2e468
commit
123cc8409e
1 changed files with 156 additions and 14 deletions
168
helperbot
168
helperbot
|
|
@ -60,20 +60,21 @@ function detect_system {
|
||||||
function base_system_upgrade {
|
function base_system_upgrade {
|
||||||
echo "${cyan}Upgrading base system.${normal}"
|
echo "${cyan}Upgrading base system.${normal}"
|
||||||
echo "${blue}Doing standard apt upgrade...${normal}"
|
echo "${blue}Doing standard apt upgrade...${normal}"
|
||||||
apt update | tee ${synth_upgrade_log}
|
apt update
|
||||||
apt upgrade -y | tee -a ${synth_upgrade_log}
|
apt upgrade -y
|
||||||
echo "${blue}Try upgrading distro base...${normal}"
|
echo "${blue}Try upgrading distro base...${normal}"
|
||||||
apt dist-upgrade -y | tee -a ${synth_upgrade_log}
|
apt dist-upgrade -y
|
||||||
echo "${blue}Apt cleanup...${normal}"
|
echo "${blue}Apt cleanup...${normal}"
|
||||||
apt clean | tee -a ${synth_upgrade_log}
|
apt clean
|
||||||
echo "${green}Base system upgraded!.${normal}"
|
echo "${green}Base system upgraded!.${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# docker container updates
|
# docker container updates
|
||||||
# reusable steps to update containers - upgrade_docker_container "/srv/docker" "name_of_service_or_folder" "compose.yaml"
|
# reusable steps to update containers - upgrade_docker_container [/srv/docker] [name_of_service_or_folder] [compose.yaml]
|
||||||
function upgrade_docker_container {
|
function upgrade_docker_container {
|
||||||
if [ -d "$1/$2" ]; then
|
if [ -d "$1/$2" ]; then
|
||||||
cd "$1"/"$2" && docker compose -f "$1/$2/$3" pull # pull the container
|
# pull the container
|
||||||
|
cd "$1"/"$2" && docker compose -f "$1/$2/$3" pull
|
||||||
docker compose -f "$1/$2/$3" down && docker compose -f "$1/$2/$3" up -d
|
docker compose -f "$1/$2/$3" down && docker compose -f "$1/$2/$3" up -d
|
||||||
else
|
else
|
||||||
echo "${red}docker:${normal} Folder $1/$2 does not exist."
|
echo "${red}docker:${normal} Folder $1/$2 does not exist."
|
||||||
|
|
@ -81,9 +82,36 @@ function upgrade_docker_container {
|
||||||
}
|
}
|
||||||
|
|
||||||
# psql vacuuming
|
# psql vacuuming
|
||||||
# reusable step to vacuum databases - postgres_vacuum [user_and_db_name] [password]
|
# reusable step to vacuum databases - postgres_vacuum [postgres-db-1] [user_and_db_name] [password]
|
||||||
function postgres_vacuum {
|
function postgres_vacuum {
|
||||||
docker exec -it postgres-db-1 /bin/bash -c "POSTGRES_PASSWORD="$2" psql -U "$1" -d "$1" -c 'VACUUM ANALYZE;'"
|
docker exec -it "$1" /bin/bash -c "POSTGRES_PASSWORD="$3" psql -U "$2" -d "$2" -c 'VACUUM ANALYZE;'"
|
||||||
|
}
|
||||||
|
|
||||||
|
# postgres_vacuum_self [postgres-db-1]
|
||||||
|
function postgres_vacuum_self {
|
||||||
|
docker exec -it "$1" /bin/bash -c "psql -U postgres -c 'VACUUM ANALYZE;'"
|
||||||
|
}
|
||||||
|
|
||||||
|
# psql backup
|
||||||
|
# reusable step to backup databases - postgres_backup [postgres-db-1] [user_and_db_name] [output_name] [$backup_working_directory]
|
||||||
|
function postgres_backup {
|
||||||
|
docker exec "$1" /bin/bash -c "pg_dump "$2" --username "$2" > "$3".sql"
|
||||||
|
docker cp "$1":/$3.sql $4/$3/$3.sql
|
||||||
|
docker exec "$1" /bin/bash -c "rm "$3".sql"
|
||||||
|
}
|
||||||
|
|
||||||
|
# redis snapshot
|
||||||
|
# tells redis to make a snapshot - redis_snapshot [whatever-redis-1]
|
||||||
|
function redis_snapshot {
|
||||||
|
docker exec $1 redis-cli SAVE
|
||||||
|
}
|
||||||
|
|
||||||
|
# backup - create folder and copy
|
||||||
|
# step that combines the process of making folders and copying files for backup
|
||||||
|
# backup_create_copy ["source files"] [subpath/to/folder] [$backup_working_directory]
|
||||||
|
function backup_create_copy {
|
||||||
|
mkdir -p $3/$2
|
||||||
|
cp -r $1 $3/$2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭───────────────────╮
|
# ╭───────────────────╮
|
||||||
|
|
@ -178,12 +206,11 @@ fi
|
||||||
# │ upgrade step │
|
# │ upgrade step │
|
||||||
# ╰──────────────╯
|
# ╰──────────────╯
|
||||||
if [ -v synth_upgrade ]; then
|
if [ -v synth_upgrade ]; then
|
||||||
timestamp=$(date +'%Y%m%d%H%M%S')
|
#timestamp=$(date +'%Y%m%d%H%M%S')
|
||||||
synth_upgrade_log=/tmp/upgrade-output-${timestamp}.txt
|
#synth_upgrade_log=/tmp/upgrade-output-${timestamp}.txt
|
||||||
# phosphorus
|
|
||||||
if [ "$synth_current_system" = "phosphorus" ]; then
|
|
||||||
echo "${blue}upgrade:${normal} Running full system upgrade for ${green}${synth_current_system}${normal}."
|
echo "${blue}upgrade:${normal} Running full system upgrade for ${green}${synth_current_system}${normal}."
|
||||||
echo "Upgrade will be logged into ${yellow}${synth_upgrade_log}${normal} if needed."
|
#echo "Upgrade will be logged into ${yellow}${synth_upgrade_log}${normal} if needed." # logging doesn't work properly - check on later
|
||||||
|
if [ "$synth_current_system" = "phosphorus" ]; then # phosphorus
|
||||||
# apt/system related upgrade
|
# apt/system related upgrade
|
||||||
base_system_upgrade
|
base_system_upgrade
|
||||||
# docker
|
# docker
|
||||||
|
|
@ -193,9 +220,124 @@ if [ -v synth_upgrade ]; then
|
||||||
upgrade_docker_container "/srv/docker" "pds" "compose.yaml"
|
upgrade_docker_container "/srv/docker" "pds" "compose.yaml"
|
||||||
# done
|
# done
|
||||||
echo "${green}System upgrade finished! beep!~${normal}"
|
echo "${green}System upgrade finished! beep!~${normal}"
|
||||||
|
elif [ "$synth_current_system" = "neptunium" ]; then # neptunium
|
||||||
|
# apt/system related upgrade
|
||||||
|
base_system_upgrade
|
||||||
|
# docker
|
||||||
|
upgrade_docker_container "/srv/docker" "mailserver" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "ejabberd" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "zitadel" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "forgejo" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "forgejo" "compose-runner.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "freshrss" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "vaultwarden" "compose-runner.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "ask-js" "compose.yaml"
|
||||||
|
# done
|
||||||
|
echo "${green}System upgrade finished! beep!~${normal}"
|
||||||
|
elif [ "$synth_current_system" = "cerium" ]; then # cerium
|
||||||
|
# apt/system related upgrade
|
||||||
|
base_system_upgrade
|
||||||
|
# docker
|
||||||
|
upgrade_docker_container "/srv/docker" "redlib" "compose.yaml"
|
||||||
|
upgrade_docker_container "/srv/docker" "safetwitch" "compose.yaml"
|
||||||
|
# done
|
||||||
|
echo "${green}System upgrade finished! beep!~${normal}"
|
||||||
|
echo "${red}Rebooting system.${normal}"
|
||||||
|
sleep 1 && systemctl reboot
|
||||||
|
elif [ "$synth_current_system" = "synthnix" ]; then # synthnix
|
||||||
|
# apt/system related upgrade
|
||||||
|
base_system_upgrade
|
||||||
|
# done
|
||||||
|
echo "${green}System upgrade finished! beep!~${normal}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ╭─────────────╮
|
||||||
|
# │ backup step │
|
||||||
|
# ╰─────────────╯
|
||||||
|
if [ -v synth_backup ]; then
|
||||||
|
if [ -v synth_vacuum ]; then
|
||||||
|
echo "${yellow}NOTICE:${normal} You've also passed in the --vacuum command. Note that upgrading also automatically vacuums the databases beforehand."
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
echo "${blue}backup:${normal} Running full system backup for ${green}${synth_current_system}${normal}."
|
||||||
|
if [ "$synth_current_system" = "phosphorus" ]; then # phosphorus
|
||||||
|
# variables
|
||||||
|
backup_local_folder=/srv/docker
|
||||||
|
backup_working_directory=/var/backups/phosphorus
|
||||||
|
backup_output_tar=phosphorus.tar
|
||||||
|
backup_media_output_tar=media_backups.tar # refers to the old local fedi media before s3 migration
|
||||||
|
# external files containing secrets
|
||||||
|
export $(grep -v '^#' /etc/secrets/b2.env | xargs)
|
||||||
|
export $(grep -v '^#' /etc/secrets/postgres.env | xargs)
|
||||||
|
# initial
|
||||||
|
mkdir -p $backup_working_directory
|
||||||
|
# database vacuuming
|
||||||
|
echo "${blue}Vacuuming postgres databases...${normal}"
|
||||||
|
postgres_vacuum_self postgres-db-1
|
||||||
|
postgres_vacuum postgres-db-1 misskey ${SHARKEY_POSTGRES_PASSWORD}
|
||||||
|
postgres_vacuum postgres-db-1 iceshrimp ${ICESHRIMP_POSTGRES_PASSWORD}
|
||||||
|
postgres_vacuum postgres-db-1 mastodon ${MASTODON_POSTGRES_PASSWORD}
|
||||||
|
# =============================================================================
|
||||||
|
# backup files - sharkey
|
||||||
|
echo "${blue}Pulling in Sharkey...${normal}"
|
||||||
|
mkdir -p $backup_working_directory/sharkey/.config
|
||||||
|
# database
|
||||||
|
postgres_backup postgres-db-1 misskey sharkey $backup_working_directory
|
||||||
|
# redis
|
||||||
|
redis_snapshot sharkey-redis-1
|
||||||
|
cp -r $backup_local_folder/sharkey/redis $backup_working_directory/sharkey
|
||||||
|
# configs, extra
|
||||||
|
cp -r $backup_local_folder/sharkey/compose.yaml $backup_working_directory/sharkey
|
||||||
|
cp -r $backup_local_folder/sharkey/.config $backup_working_directory/sharkey
|
||||||
|
# =============================================================================
|
||||||
|
# iceshrimp
|
||||||
|
echo "${blue}Pulling in Iceshrimp...${normal}"
|
||||||
|
mkdir -p $backup_working_directory/iceshrimp/config
|
||||||
|
# database
|
||||||
|
postgres_backup postgres-db-1 iceshrimp iceshrimp $backup_working_directory
|
||||||
|
# configs, extra
|
||||||
|
cp -r $backup_local_folder/iceshrimp/compose.yaml $backup_working_directory/iceshrimp
|
||||||
|
cp -r $backup_local_folder/iceshrimp/config $backup_working_directory/iceshrimp
|
||||||
|
# =============================================================================
|
||||||
|
# mastodon
|
||||||
|
echo "${blue}Pulling in Mastodon...${normal}"
|
||||||
|
mkdir -p $backup_working_directory/mastodon/.config
|
||||||
|
# database
|
||||||
|
postgres_backup postgres-db-1 mastodon mastodon $backup_working_directory
|
||||||
|
# redis
|
||||||
|
redis_snapshot mastodon-redis-1
|
||||||
|
cp -r $backup_local_folder/mastodon/redis $backup_working_directory/mastodon
|
||||||
|
# configs, extra
|
||||||
|
cp -r $backup_local_folder/mastodon/compose.yaml $backup_working_directory/mastodon
|
||||||
|
cp -r $backup_local_folder/mastodon/.config $backup_working_directory/mastodon
|
||||||
|
# =============================================================================
|
||||||
|
# pds
|
||||||
|
echo "${blue}Pulling in PDS...${normal}"
|
||||||
|
mkdir -p $backup_working_directory/pds
|
||||||
|
# there isn't a native way to "backup" the pds, so we shut it off and copy it
|
||||||
|
docker compose -f $backup_local_folder/pds/compose.yaml down
|
||||||
|
cp -r $backup_local_folder/pds/pds $backup_working_directory/pds
|
||||||
|
docker compose -f $backup_local_folder/pds/compose.yaml up -d
|
||||||
|
# configs, extra
|
||||||
|
cp -r $backup_local_folder/pds/compose.yaml $backup_working_directory/pds
|
||||||
|
# =============================================================================
|
||||||
|
# unset secrets
|
||||||
|
unset $(grep -v '^#' /etc/secrets/b2.env | sed -E 's/(.*)=.*/\1/' | xargs)
|
||||||
|
unset $(grep -v '^#' /etc/secrets/postgres.env | sed -E 's/(.*)=.*/\1/' | xargs)
|
||||||
|
elif [ "$synth_current_system" = "neptunium" ]; then # neptunium
|
||||||
|
postgres_vacuum_self postgres-db-1
|
||||||
|
elif [ "$synth_current_system" = "cerium" ]; then # cerium
|
||||||
|
postgres_vacuum_self postgres-db-1
|
||||||
|
elif [ "$synth_current_system" = "synthnix" ]; then # synthnix
|
||||||
|
# as synthnix doesn't really include much and serves as a place for members
|
||||||
|
# we just need to back up the home directory here
|
||||||
|
#
|
||||||
|
# WIP
|
||||||
|
fi
|
||||||
|
echo "${green}System backup finished! beep!~${normal}"
|
||||||
|
fi
|
||||||
|
|
||||||
#if [[ -v system_vacuum ]]; then
|
#if [[ -v system_vacuum ]]; then
|
||||||
# echo "${yellow}NOTICE:${normal} You've also passed in the --vacuum command. Note that upgrading also automatically vacuums the databases beforehand."
|
# echo "${yellow}NOTICE:${normal} You've also passed in the --vacuum command. Note that upgrading also automatically vacuums the databases beforehand."
|
||||||
# sleep 1
|
# sleep 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue