run backup script by unprivileged user

This commit is contained in:
0x90.space 2023-12-07 21:55:15 +00:00
parent 45bf1d582e
commit 31924ab242

View file

@ -1,20 +1,26 @@
#!/bin/bash #!/bin/bash
if [ $(id -u) -eq 0 ]
then
echo "script is run by kanboard user now, this cronjob is obsolete"
exit 0
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR cd $DIR
. ./.env . ./.env
# stop the containers to make sure the data doesn't change during backup. # stop the containers to make sure the data doesn't change during backup.
XDG_RUNTIME_DIR=/run/user/1002 su synthikat -c "podman stop wordpress_wordpress_1 wordpress_db_1" podman stop wordpress_wordpress_1 wordpress_db_1
# Example backup command: # Example backup command:
# backup: is the remote backup server, defined in ~/.ssh/config - ends with a : # backup: is the remote backup server, defined in ~/.ssh/config - ends with a :
# repositories-borg/synthikat is the path on the remote server - ends with a :: # repositories-borg/synthikat is the path on the remote server - ends with a ::
# 'backup{now:%Y%m%d}' is the backup name, this includes today's date in the name # 'backup{now:%Y%m%d}' is the backup name, this includes today's date in the name
# the rest are the file paths. You can append as many as you want. # the rest are the file paths. You can append as many as you want.
borg create --stats --progress cyberbackup:repositories-borg/synthikat::'backup{now:%Y%m%d-%M}' ../wp-content ../db_data podman unshare borg create --stats --progress cyberbackup:repositories-borg/synthikat::'backup{now:%Y%m%d-%M}' ../wp-content ../db_data
# restart the containers # restart the containers
XDG_RUNTIME_DIR=/run/user/1002 su synthikat -c "podman start wordpress_wordpress_1 wordpress_db_1" podman start wordpress_wordpress_1 wordpress_db_1
# Delete all the backups which are too old, to save space in the long term. # Delete all the backups which are too old, to save space in the long term.
borg prune --keep-daily=7 --keep-weekly=4 cyberbackup:repositories-borg/synthikat borg prune --keep-daily=7 --keep-weekly=4 cyberbackup:repositories-borg/synthikat