Compare commits
6 commits
a4660ee328
...
ce746ad72b
Author | SHA1 | Date | |
---|---|---|---|
ce746ad72b | |||
6ffb34a96b | |||
3081cdea2e | |||
87f5e39040 | |||
f5982bb7df | |||
0acdced260 |
5 changed files with 32 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
*_pass.txt
|
*_pass.txt
|
||||||
*.env
|
*.env
|
||||||
|
rclone.conf
|
||||||
|
|
|
@ -43,9 +43,11 @@ else
|
||||||
destination="${1}"
|
destination="${1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
namespace="ix-gitea-2"
|
||||||
|
|
||||||
# Retrieve container names
|
# Retrieve container names
|
||||||
base_container="$( docker ps --format '{{.Names}}' | grep -E 'gitea_gitea-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
base_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep -E 'gitea-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
||||||
database_container="$( docker ps --format '{{.Names}}' | grep 'postgres_gitea-cnpg-main-1' )"
|
database_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep 'gitea-2-cnpg-main-2' )"
|
||||||
|
|
||||||
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
||||||
>&2 printf "Error: Not all containers could be found.\n"
|
>&2 printf "Error: Not all containers could be found.\n"
|
||||||
|
@ -57,7 +59,7 @@ set -e
|
||||||
|
|
||||||
# Enable maintenance mode
|
# Enable maintenance mode
|
||||||
# Flush queues
|
# Flush queues
|
||||||
docker exec "${base_container}" gitea manager flush-queues
|
k3s kubectl exec "${base_container}" --namespace "${namespace}" -- gitea manager flush-queues
|
||||||
# TODO Pause queues
|
# TODO Pause queues
|
||||||
|
|
||||||
# Database backup
|
# Database backup
|
||||||
|
@ -68,7 +70,7 @@ host_database_backupfile="${destination}/${database_backupfile}"
|
||||||
|
|
||||||
# Backup the database
|
# Backup the database
|
||||||
>&2 echo 'Backing up database'
|
>&2 echo 'Backing up database'
|
||||||
docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'gitea' -cwv -h 'localhost' -U 'gitea' > "${host_database_backupfile}"
|
k3s kubectl exec "${database_container}" --namespace "${namespace}" -- env $(cat "${env_file:=.env}" | xargs) pg_dump 'gitea' -cwv -h 'localhost' -U 'gitea' > "${host_database_backupfile}"
|
||||||
|
|
||||||
# Disable maintenance mode
|
# Disable maintenance mode
|
||||||
# TODO Continue queues
|
# TODO Continue queues
|
||||||
|
|
|
@ -39,12 +39,14 @@ else
|
||||||
destination="${1}"
|
destination="${1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
namespace="ix-nextcloud-2"
|
||||||
|
|
||||||
# Filename for database backup
|
# Filename for database backup
|
||||||
database_backupfile="nextcloud-sqlbkp_$(date +'%Y%m%d').bak"
|
database_backupfile="nextcloud-sqlbkp_$(date +'%Y%m%d').bak"
|
||||||
|
|
||||||
# Retrieve container names
|
# Retrieve container names
|
||||||
base_container="$( docker ps --format '{{.Names}}' | grep -E 'nextcloud-2_nextcloud-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
base_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep -E 'nextcloud-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
||||||
database_container="$( docker ps --format '{{.Names}}' | grep postgres_nextcloud-2-cnpg-main-1 )"
|
database_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep 'cnpg-main' )"
|
||||||
|
|
||||||
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
||||||
>&2 printf "Error: Not all containers could be found.\n"
|
>&2 printf "Error: Not all containers could be found.\n"
|
||||||
|
@ -55,21 +57,21 @@ fi
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Turn on maintenance mode
|
# Turn on maintenance mode
|
||||||
docker exec "${base_container}" php occ maintenance:mode --on
|
k3s kubectl exec "${base_container}" --namespace "${namespace}" -- php occ maintenance:mode --on
|
||||||
|
|
||||||
# Database backup
|
# Database backup
|
||||||
echo 'Backing up database'
|
echo 'Backing up database'
|
||||||
host_database_backupfile="${destination}/${database_backupfile}"
|
host_database_backupfile="${destination}/${database_backupfile}"
|
||||||
docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'nextcloud' -cwv -h 'localhost' -U 'nextcloud' > "${host_database_backupfile}"
|
k3s kubectl exec "${database_container}" --namespace "${namespace}" -- env $(cat "${env_file:=.env}" | xargs) pg_dump 'nextcloud' -cwv -h 'localhost' -U 'nextcloud' > "${host_database_backupfile}"
|
||||||
|
|
||||||
# Files backup
|
# Files backup
|
||||||
for file in 'config' 'themes'; do
|
for file in 'config' 'themes'; do
|
||||||
printf "Copying %s\n" "${file}"
|
printf "Copying %s\n" "${file}"
|
||||||
docker cp -a "${base_container}":"/var/www/html/${file}" "${destination}"
|
k3s kubectl --namespace "${namespace}" cp "${base_container}":"/var/www/html/${file}" "${destination}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Turn off maintenance mode
|
# Turn off maintenance mode
|
||||||
docker exec "${base_container}" php occ maintenance:mode --off
|
k3s kubectl exec "${base_container}" --namespace "${namespace}" -- php occ maintenance:mode --off
|
||||||
|
|
||||||
# Backup cleanup
|
# Backup cleanup
|
||||||
# Only keep 30 days of backups
|
# Only keep 30 days of backups
|
||||||
|
|
10
scripts/rclone.conf.example
Normal file
10
scripts/rclone.conf.example
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[overlay]
|
||||||
|
type = chunker
|
||||||
|
remote = Nicole:
|
||||||
|
|
||||||
|
[Nicole]
|
||||||
|
type = ftp
|
||||||
|
host = 192.168.0.20
|
||||||
|
user = USERNAME
|
||||||
|
pass = CHANGEME
|
||||||
|
|
|
@ -41,9 +41,11 @@ else
|
||||||
destination="${1}"
|
destination="${1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
namespace="ix-vaultwarden-2"
|
||||||
|
|
||||||
# Retrieve container names
|
# Retrieve container names
|
||||||
base_container="$( docker ps --format '{{.Names}}' | grep -E 'vaultwarden-2_vaultwarden-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
base_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep -E 'vaultwarden-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
||||||
database_container="$( docker ps --format '{{.Names}}' | grep postgres_vaultwarden-2-cnpg-main-1 )"
|
database_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep 'vaultwarden-2-cnpg-main-1' )"
|
||||||
|
|
||||||
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
||||||
>&2 printf "Error: Not all containers could be found.\n"
|
>&2 printf "Error: Not all containers could be found.\n"
|
||||||
|
@ -59,14 +61,14 @@ set -e
|
||||||
database_backupfile="vaultwarden-sqlbkp_$(date +'%Y%m%d').bak"
|
database_backupfile="vaultwarden-sqlbkp_$(date +'%Y%m%d').bak"
|
||||||
host_database_backupfile="${destination}/${database_backupfile}"
|
host_database_backupfile="${destination}/${database_backupfile}"
|
||||||
|
|
||||||
# Create backup file in docker container
|
# Create backup file in Kubernetes pod
|
||||||
echo 'Backing up database'
|
echo 'Backing up database'
|
||||||
docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'vaultwarden' -cwv -h 'localhost' -U 'vaultwarden' > "${host_database_backupfile}"
|
k3s kubectl exec "${database_container}" --namespace "${namespace}" -- env $(cat "${env_file:=.env}" | xargs) pg_dump 'vaultwarden' -cwv -h 'localhost' -U 'vaultwarden' > "${host_database_backupfile}"
|
||||||
|
|
||||||
# Files backup
|
# Files backup
|
||||||
for file in 'attachments' 'sends' 'rsa_key.pem' 'rsa_key.pub.pem'; do # 'config.json'
|
for file in 'attachments' 'sends' 'rsa_key.pem' 'rsa_key.pub.pem'; do # 'config.json'
|
||||||
printf 'Copying %s\n' "${file}"
|
printf 'Copying %s\n' "${file}"
|
||||||
docker cp -a "${base_container}":"/data/${file}" "${destination}"
|
k3s kubectl --namespace "${namespace}" cp "${base_container}":"/data/${file}" "${destination}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Backup cleanup
|
# Backup cleanup
|
||||||
|
|
Loading…
Reference in a new issue