Code: Alles auswählen
#!/bin/sh
name=$(date +%m-%d-%Y_%R)_forumDB.sql
pfad=/shared/temp/forum-mysql
#
#alte Dateien bis auf 20 l�chen
#
list=$(ls -lt $pfad | tail -n +20 | cut -d" " -f17)
for i in $list; do
rm $pfad/$i
done
mysqldump -u knecht --password=geheim -B forum2 > $pfad/$name
rm $pfad/forumDB.sql
ln -s $pfad/$name $pfad/forumDB.sql
Aber in der Praxis sieht das so aus: (crontab als root, alle Stunden)
Code: Alles auswählen
himself:~# ls -l /shared/temp/forum-mysql/
total 13877
-rw-r--r-- 1 root root 7076743 Feb 1 05:59 02-01-2005_05:59_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 20:00 02-01-2005_19:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 21:00 02-01-2005_20:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 22:00 02-01-2005_21:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 23:00 02-01-2005_22:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 00:00 02-01-2005_23:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 01:00 02-02-2005_00:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 02:00 02-02-2005_01:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 03:00 02-02-2005_02:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 04:00 02-02-2005_03:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 05:00 02-02-2005_04:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 06:00 02-02-2005_05:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 07:00 02-02-2005_06:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 08:00 02-02-2005_07:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 09:00 02-02-2005_08:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 10:00 02-02-2005_09:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 11:00 02-02-2005_10:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 12:00 02-02-2005_11:00_forumDB.sql
-rw-r--r-- 1 root root 7130823 Feb 2 12:00 02-02-2005_12:00_forumDB.sql
lrwxrwxrwx 1 root root 53 Feb 2 12:00 forumDB.sql -> /shared/temp/forum-mysql/02-02-2005_12:00_forumDB.sql
Code: Alles auswählen
himself:~# ./db_sichern.sh
himself:~# ls -l /shared/temp/forum-mysql/
total 20841
-rw-r--r-- 1 root root 7076743 Feb 1 05:59 02-01-2005_05:59_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 21:00 02-01-2005_20:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 22:00 02-01-2005_21:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 1 23:00 02-01-2005_22:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 00:00 02-01-2005_23:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 01:00 02-02-2005_00:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 02:00 02-02-2005_01:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 03:00 02-02-2005_02:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 04:00 02-02-2005_03:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 05:00 02-02-2005_04:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 06:00 02-02-2005_05:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 07:00 02-02-2005_06:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 08:00 02-02-2005_07:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 09:00 02-02-2005_08:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 10:00 02-02-2005_09:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 11:00 02-02-2005_10:00_forumDB.sql
-rw-r--r-- 1 root root 0 Feb 2 12:00 02-02-2005_11:00_forumDB.sql
-rw-r--r-- 1 root root 7130823 Feb 2 12:00 02-02-2005_12:00_forumDB.sql
-rw-r--r-- 1 root root 7130935 Feb 2 12:06 02-02-2005_12:06_forumDB.sql
lrwxrwxrwx 1 root root 53 Feb 2 12:06 forumDB.sql -> /shared/temp/forum-mysql/02-02-2005_12:06_forumDB.sql
Sebastian