Attached files should be in root and then edit crontab and put in the following
05 00 * * * /root/backup.daily.sh > /root/wikibackup/daily.log 2>&1
20 00 * * 0 /root/backup.weekly.sh > /root/wikibackup/weekly.log 2>&1
40 00 1 * * /root/backup.monthly.sh > /root/wikibackup/monthly.log 2>&1
Result: After one year you will have
12 Monthly backups
5 or 4 weekly backups
7 Daily backups
The script checks if there are older backups then these parameters and if there are then it deletes them.
#!/bin/bash
# What folder to put the temporary backup files in
backup_dir="/tmp/wikibackup"
# What folder to store the complete backup.tar.gz in
storage="/root/wikibackup/daily"
# Create backup dir if it doesn't exist
if [ ! -e $backup_dir ]
then
echo "### Creating $backup_dir folder ###"
/bin/mkdir -v $backup_dir
else
echo "### Found $backup_dir, proceeding... ###"
fi
# Today's date
today=`/bin/date +%Y-%m-%d`
echo "### Dumping MySQL tables ###"
/usr/bin/mysqldump -v -u root -ppassword wikidb > $backup_dir/wikidb.$today.sql
echo "### Copying configuration files ###"
/bin/cp -v /var/www/deki-hayes/LocalSettings.php $backup_dir
if [ -f "/var/www/deki-hayes/AdminSettings.php" ]
then
echo "### Copying AdminSettings.php ###"
/bin/cp -v /var/www/deki-hayes/AdminSettings.php $backup_dir
fi
/bin/cp -v /etc/dekiwiki/mindtouch.deki.startup.xml $backup_dir
echo "### Collecting attachments ###"
/bin/tar -cvpf $backup_dir/attachments.tar /var/www/deki-hayes/attachments/ > $backup_dir/attachments.log
# Create backup dir if it doesn't exist
if [ ! -e $storage ]
then
echo "### Creating $storage folder ###"
/bin/mkdir -v $storage
else
echo "### Found $storage, proceeding... ###"
fi
echo "### Compressing backup files ###"
/bin/tar -czvpf $storage/backup.$today.tar.gz $backup_dir
echo "### Removing temporary backup files and folders ###"
/bin/rm -v $backup_dir/*
/bin/rmdir -v $backup_dir
echo "### Removing old backup files ###"
find $storage/ -type f -name "backup.*.tar.gz" -mtime +7 -exec rm -v {} \;
echo "### Done ###"
#!/bin/bash
# What folder to store the complete backup.tar.gz in
storage="/root/wikibackup/weekly"
# Create weekly dir if it doesn't exist
if [ ! -e $storage ]
then
echo "### Creating $storage folder ###"
/bin/mkdir -v $storage
else
echo "### Found $storage, proceeding... ###"
fi
echo "### Copy weekly backup file ###"
find $storage/../daily -type f -name "backup.*.tar.gz" -mtime 0 -exec cp -uv {} $storage/ \;
echo "### Remove old backup files ###"
find $storage/ -type f -name "backup.*.tar.gz" -mtime +31 -exec rm -v {} \;
echo "### Done ###"
#!/bin/bash # What folder to store the complete backup.tar.gz in
storage="/root/wikibackup/monthly"
# Create weekly dir if it doesn't exist
if [ ! -e $storage ]
then
echo "### Creating $storage folder ###"
/bin/mkdir -v $storage
else
echo "### Found $storage, proceeding... ###"
fi
echo "### Copy weekly backup file ###"
find $storage/../weekly/ -type f -name "backup.*.tar.gz" -mtime +6 -exec cp -vu {} $storage/ \;
echo "### Remove old backup files ###"
find $storage/ -type f -name "backup.*.tar.gz" -mtime +365 -exec rm -v {} \;
echo "### Done ###"
| File | Size | Date | Attached by | |||
|---|---|---|---|---|---|---|
| backup.daily.sh No description | 1632 bytes | 15:12, 28 Oct 2008 | mrfredrik | Actions | ||
| backup.monthly.sh No description | 603 bytes | 15:13, 28 Oct 2008 | mrfredrik | Actions | ||
| backup.weekly.sh No description | 598 bytes | 15:13, 28 Oct 2008 | mrfredrik | Actions | ||