linuxkurs/beispiele/11/file-backup.sh

58 lines
892 B
Bash
Raw Normal View History

2019-02-01 08:51:57 +01:00
#!/bin/bash
NOW="$(date +"%d-%m-%Y")"
# websites folder
WEBSITESDIR="."
# local backup folder
BACKUPDIR="./backups"
if [ ! -d $BACKUPDIR ]; then
mkdir $BACKUPDIR
fi
# Array
declare -a liste
# Unterverzeichnisse von html die gebackuppt werden sollen
liste=(
"omikron"
"amazon.de"
"spiegel.de"
"google.de"
"omikron/china"
"omikron/swiss"
)
# websites
function create_websites_backup {
cd $WEBSITESDIR
for i in "${liste[@]}"; do
if [ -d $i ]; then
tag=$(echo $i | sed 's/\//-/')
tar -zcf $BACKUPDIR/$tag-$NOW.tar.gz $WEBSITESDIR/$i
else
echo "File or Directory $i not found!\n"
fi
done
}
function do_sql_backup {
cd $BACKUPDIR
tag=db-$4-$NOW
mysqldump --opt --add-drop-table -h$1 -u$2 -p$3 $4 | gzip > $tag.sql.gz
}
#do_sql_backup "localhost" "db_user" "secret_pw" "db_name"
create_websites_backup
cd -