40 lines
978 B
Bash
Executable File
40 lines
978 B
Bash
Executable File
#! /bin/bash
|
|
|
|
if [ -f config.properties ]; then
|
|
source config.properties
|
|
elif [ -f /etc/autobackup/config.properties ]; then
|
|
source /etc/autobackup/config.properties
|
|
else
|
|
>&2 echo Could not find config.properties
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f backup.list ]; then
|
|
SOURCE_LIST_FILE=backup.list
|
|
elif [ -f /etc/autobackup/backup.list ]; then
|
|
SOURCE_LIST_FILE=/etc/autobackup/backup.list
|
|
else
|
|
>&2 echo Could not find backup.list
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
DATE=$(date "+%Y%m%d")
|
|
|
|
while IFS= read -r SOURCE; do
|
|
SOURCE="${SOURCE%%#*}"
|
|
SOURCE=$(echo "$SOURCE" | sed -re 's/^[[:blank:]]+|[[:blank:]]+$//g')
|
|
|
|
if [ -z "$SOURCE" ]; then
|
|
continue
|
|
fi
|
|
|
|
rsync --archive --relative --link-dest="$BACKUP_DIR/previous" "$SOURCE" "$BACKUP_DIR/backup_$DATE"
|
|
done <"$SOURCE_LIST_FILE"
|
|
|
|
rm -f "$BACKUP_DIR/previous"
|
|
ln -s "backup_$DATE" "$BACKUP_DIR/previous"
|
|
|
|
find "$BACKUP_DIR" -maxdepth 1 -type d -mtime "+$RETENTION_DAYS" -exec rm -r {} \;
|