diff --git a/beispiele/11/file-backup.sh b/beispiele/11/file-backup.sh new file mode 100644 index 0000000..e30e873 --- /dev/null +++ b/beispiele/11/file-backup.sh @@ -0,0 +1,57 @@ +#!/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 - + + diff --git a/beispiele/11/helper/make-dirs.sh b/beispiele/11/helper/make-dirs.sh new file mode 100644 index 0000000..c0d4cd8 --- /dev/null +++ b/beispiele/11/helper/make-dirs.sh @@ -0,0 +1,25 @@ +#script zur erstellung einer Test Umgebung + +declare -a liste + +# Unterverzeichnisse von html die gebackuppt werden sollen +liste=( + "omikron" + "amazon.de" + "spiegel.de" + "google.de" + "omikron/china" + "omikron/swiss" + ) + + +# Meat +for i in "${liste[@]}"; do + mkdir -p $i + echo "

hallo test

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, + quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse + cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non + proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

" > $i/index.html +done \ No newline at end of file diff --git a/beispiele/11/rsync-backup.sh b/beispiele/11/rsync-backup.sh new file mode 100644 index 0000000..c3242f6 --- /dev/null +++ b/beispiele/11/rsync-backup.sh @@ -0,0 +1,16 @@ + +#!/bin/bash + +USERNAME=XXX +REMOTE_HOST=XXX + +# rsync options +# -a = Archive Mode +# -v = Verbode - für das log file +# -z = Compress +# -e = specify the remote shell to use +/usr/bin/rsync -avze 'ssh -i /home/$USERNAME/.ssh/rsync-key' $REMOTE_HOST:/home/$USERNAME/backups/* /local/backup/dir/ >> backup.log 2>&1 + +# delete backups older than 10 days +#find /local/backup/dir -mtime +10 -type f -delete +