#!/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" # # 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 # setup adminapi/objects declare -a folders=($folderlist) cd ${pathtown} lstfile="" for folder in "${folders[@]}"; do lstfile="${lstfile} ${tribe}/${mainfolder}/${folder}" done tar -czf ${tribe}/backups/${prefix}.${mainfolder}.tar.gz ${lstfile}