Skip to content

Instantly share code, notes, and snippets.

@malias
Last active December 21, 2015 19:19
Show Gist options
  • Save malias/f528d31468a9c1dbb3a3 to your computer and use it in GitHub Desktop.
Save malias/f528d31468a9c1dbb3a3 to your computer and use it in GitHub Desktop.
Make daily backups from your web server and delete them after 30 day
#!/bin/bash
#
# Mit diesem Script kann eine gesamte Webseite gesichert werden.
# Das Zielverzeichnis (backupTargetPath) muss zuerst erstellt werden:
# $ cd /home/BENUTZERNAME/
# $ mkdir websitebackup
# Datum; Bitte nicht anpassen
date=`/bin/date "+%Y-%m-%d-%H%M%S"`
# Default: 30 ; Alle backups, die aelter als 30 Tage sind werden geloescht.
keepBackupDays=30
# Pfad Zielverzeichnis
backupTargetPath='/home/BENUTZERNAME/websitebackup/';
# Pfad Quellverzeichnis
backupFolder='/home/BENUTZERNAME/public_html';
# Backup wird erstellt; Bitte nicht anpassen
tar cvfz $backupTargetPath/WebSiteBackup.$date.tar.gz $backupFolder
# Dateien im Zielverzeichnis, die aelter als 'keepBackupDays(Default 30)' werden geloescht; Bitte nicht anpassen
ls -1 $backupTargetPath | while read file
do
file=${backupTargetPath}${file}
if [[ -f $file ]] && [[ "${file}" =~ ".*\.tar\.gz$" ]] && [[ `stat -c %Y $file` < `date --date="${keepBackupDays} days ago" +%s` ]]
then
rm -fv $file
fi
done;
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment