Tips and tricks

Backupscript för mysql

#!/bin/bash

dbuser=”USERNAME”
dbpass=”PASSWORD”
db=”wordpressdata”
tmppath=”/tmp”
dbpath=”/db_backups/”
timestamp=$( date “+%Y-%m-%d_%H-%M” )
filename=”wordpressdata_$timestamp.sql.gz”
host=”X.X.X.X”

backup=$( mysqldump –events –routines –single-transaction –skip-comments –quick -u $dbuser -p$dbpass -h$host $db | gzip > $tmppath/$filename )
countbackups=$( ls $dbpath | wc -l )

# Check if /db_backups contains more than 10 backups
if [[ $countbackups -ge 10 ]];
then
# Get the oldest backup
getOldest=$( ls -lat $dbpath | awk ‘{print $9}’ | grep sql.gz | tail -1 )
# Remove the oldest backup
rmOldest=$( rm $dbpath/$getOldest )
fi

# Copy backup to archive
mvBackup=$( mv $tmppath/$filename $dbpath )

___________________________________________________________________________________________________

lägg in ett cronjob när du vill att backupen ska gå.
nästa inlägg blir hur man enkelt kontrollerar att backupen har gått med nagios