This commit is contained in:
2022-10-23 01:45:06 +02:00
parent e7652183b9
commit 6cf379189e
5 changed files with 11738 additions and 0 deletions

36
pibackup.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# check if running
me="$(basename "$0")";
result=`ps aux | grep -i $me | grep -v "grep" | wc -l`
echo "running: $result"
if [ $result -gt 2 ]
then
exit
fi
# delete
ROOTDIR=/home/pi/projects/pibackup
STATUSFILE=$ROOTDIR/status.log
ERRORFILE=$ROOTDIR/error.log
if [ -f "${STATUSFILE}" ]; then
sudo rm ${STATUSFILE}
fi
# DB
BACKUPDIR=/mnt/NASbarracuda1TB/backup/pi2/db/`date +"%Y-%m-%d-%H-%M-%S"`
mkdir -p ${BACKUPDIR}
for DB in $(mysql -e 'show databases' -s --skip-column-names -u pi2 -p13371337); do
mysqldump --single-transaction -h localhost -u pi2 -p13371337 --opt $DB > ${BACKUPDIR}/$DB.sql
done
# seafile
sudo rsync -azh --log-file=${ROOTDIR}/status.log --exclude={'seafile-data','seafile-server-latest'} /opt/seafile/ /mnt/NASbarracuda1TB/backup/pi2/seafile
# external piseafile (seafile-data & gitea)
sudo rsync -azh --log-file=${ROOTDIR}/status.log /mnt/piseafile/ /mnt/NASbarracuda1TB/backup/pi2/piseafile
# copy logs
cp $ERRORFILE /mnt/NASbarracuda1TB/backup/pi2/error.log
cp $STATUSFILE /mnt/NASbarracuda1TB/backup/pi2/status.log