Some old stuff
This commit is contained in:
5
bash/cronbackup/backup.log
Normal file
5
bash/cronbackup/backup.log
Normal file
@@ -0,0 +1,5 @@
|
||||
Mounting /media/backup_mirror/ ...
|
||||
Checking for expired backups blogAPI.git (2)
|
||||
Checking for expired backups wenku8.git (2)
|
||||
Checking for expired backups wenku8 (4)
|
||||
Checking for expired backups file (2)
|
79
bash/cronbackup/backup.sh
Normal file
79
bash/cronbackup/backup.sh
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
# IO Redirection
|
||||
exec > backup.log
|
||||
|
||||
# exec 2> backup_err.log
|
||||
|
||||
BAKDIR=/media/backup_mirror
|
||||
|
||||
if ! grep -qs $BAKDIR /proc/mounts; then
|
||||
echo Mounting $BAKDIR ...
|
||||
mount $BAKDIR
|
||||
fi
|
||||
|
||||
|
||||
while read line; do
|
||||
|
||||
# substring first char
|
||||
firstChr=${line::1}
|
||||
|
||||
# if line is not empty and does not start with "#"
|
||||
|
||||
if [ $firstChr ] && [ $firstChr != "#" ]; then
|
||||
|
||||
# file and arguments are seperated by ":"
|
||||
IFS=':' read -ra ARGS <<< "$line"
|
||||
|
||||
# Get file
|
||||
FILE=${ARGS[0]}
|
||||
|
||||
# if file exists
|
||||
if [ -a $FILE ]; then
|
||||
|
||||
# filename
|
||||
FILENAME=$(basename $FILE)
|
||||
|
||||
# set the backup name YYYYMMDDhhmm
|
||||
BACKUPFILE=$(date +$FILENAME.%Y%m%d%H%M.tar.gz)
|
||||
|
||||
# exclude file
|
||||
EXCLUDE="exclude/${ARGS[1]}"
|
||||
|
||||
if [ -f $EXCLUDE ]; then
|
||||
tar zcf "$BAKDIR/$BACKUPFILE" -C "$FILE/../" $FILENAME -X $EXCLUDE
|
||||
else
|
||||
tar zcf "$BAKDIR/$BACKUPFILE" -C "$FILE/../" $FILENAME
|
||||
fi
|
||||
|
||||
# count backup file
|
||||
fCount=$(ls $BAKDIR/*$FILENAME*.gz|wc -l)
|
||||
|
||||
echo Checking for expired backups $FILENAME \($fCount\)
|
||||
|
||||
# keep up to 7 backup
|
||||
if [ $fCount -ne 7 ]; then
|
||||
|
||||
# delete count
|
||||
dCount=`expr $fCount - 7`
|
||||
|
||||
# loop over files
|
||||
for files in $BAKDIR/*$FILENAME*.gz; do
|
||||
if [ 0 -lt $dCount ]; then
|
||||
|
||||
# remove expired file
|
||||
rm "$files";
|
||||
|
||||
# dCount --
|
||||
dCount=$((dCount-1));
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
# echo --\> $line
|
||||
done < backup_list
|
||||
|
||||
umount $BAKDIR
|
0
bash/cronbackup/backup_err.log
Normal file
0
bash/cronbackup/backup_err.log
Normal file
8
bash/cronbackup/backup_list
Normal file
8
bash/cronbackup/backup_list
Normal file
@@ -0,0 +1,8 @@
|
||||
# git backups
|
||||
/srv/repo/blogAPI.git
|
||||
/srv/repo/wenku8.git
|
||||
/wenku8-android.git
|
||||
|
||||
# www
|
||||
/var/www/wenku8
|
||||
/var/www/file:file.txt
|
2
bash/cronbackup/exclude/file.txt
Normal file
2
bash/cronbackup/exclude/file.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
blog
|
||||
public
|
Reference in New Issue
Block a user