2024-10-30 15:20:47 +00:00
# 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)
2024-10-31 11:05:42 +00:00
# param $5 folderlist split by a space in doublequote "folder1 folder2" if "*" or empty then backup the full mainfolder
2024-10-30 15:20:47 +00:00
#
# 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
2024-10-31 11:05:42 +00:00
pathtown = " $1 "
tribe = " $2 "
mainfolder = " $3 "
prefix = " $4 "
if [ [ " $prefix " = = "dayname" ] ] ; then
2024-10-30 15:20:47 +00:00
prefix = $( date +%A)
fi
folderlist = $5
2024-10-31 11:05:42 +00:00
if [ [ " $folderlist " = = "*" || -z " $folderlist " ] ] ; then
2024-11-01 19:01:48 +00:00
#carefull lstfile must start by a space
lstfile = " ${ tribe } / ${ mainfolder } "
2024-10-31 11:05:42 +00:00
else
lstfile = ""
for folder in ${ folderlist } ; do
lstfile = " ${ lstfile } ${ tribe } / ${ mainfolder } / ${ folder } "
done
fi
cd " $pathtown "
2024-11-01 19:01:48 +00:00
tar -czf " ${ tribe } /backups/ ${ prefix } . ${ mainfolder } .tar.gz " $lstfile
2024-10-31 11:05:42 +00:00
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