adminapi/backup.sh
2024-11-18 15:49:20 +01:00

48 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# backup each night
# param $1 path to town name
# param $2 tribe name
# param $3 mainfolder that contain folderlist store this in tribe/backup/mainfolder.ter.gz
# param $4 prefix special keyword dayname is convert to $(date +%A)
# param $5 folderlist split by a space in doublequote "folder1 folder2" if "*" or empty then backup the full mainfolder
#
# Exemple:
# For setup
#. /media/phil/usbfarm/apxtowns/dev-ants/adminapi/backup.sh /media/phil/usbfarm/apxtowns/dev-ants adminapi objects setup. "nations options pagans towns tplstrings wwws"
#. /media/phil/usbfarm/apxtowns/dev-ants/adminapi/backup.sh /media/phil/usbfarm/apxtowns/dev-ants adminapi apxtri setup. "middlewares models routes apidoc_adminapi.json apxchat.js apxtri.js package.json"
# For backup
#. /media/phil/usbfarm/apxtowns/dev-ants/adminapi/backup.sh /media/phil/usbfarm/apxtowns/dev-ants adminapi objects dayname "persons"
#
#
# add in crontab each day at 2h00 with echo "0 2 * * ${pathtown}/${town}/adminapi/backup.sh ${pathtown}/${town} ${tribe} objects setup. \"list of object to backup\"" | crontab -
# add in crontab each day at 2h10 with echo "10 2 * * ${pathtown}/${town}/adminapi/backup.sh ${pathtown}/${town} ${tribe} objects $(date +A%) \"list of object to backup\"" | crontab -
# add it for setup at least
pathtown="$1"
tribe="$2"
mainfolder="$3"
prefix="$4"
if [[ "$prefix" == "dayname" ]]; then
prefix=$(date +%A)
fi
folderlist=$5
if [[ "$folderlist" == "*" || -z "$folderlist" ]]; then
#carefull lstfile must start by a space
lstfile=" ${tribe}/${mainfolder}"
else
lstfile=""
for folder in ${folderlist}; do
lstfile="${lstfile} ${tribe}/${mainfolder}/${folder}"
done
fi
cd "$pathtown"
tar -czf "${tribe}/backups/${prefix}.${mainfolder}.tar.gz"$lstfile
if [ $? -eq 0 ]; then
echo "Archive created successfully ${tribe}/backups/${prefix}.${mainfolder}.tar.gz"
else
echo "Error creating archive ${tribe}/backups/${prefix}.${mainfolder}.tar.gz"
fi