I use simple set of shell commands to in order to create mysqldumps daily. The script is called by cron daemon. It looks like:
presentdate="`date +%d-%m-%Y_%H:%M.%S`"
basedir="/var/db_my_backup"
mysqldump -u username -ppassword --all-databases |
gzip -9 -c > $basedir/mysqlbackup.$presentdate.sql.gz |
find -L $basedir/'*' -type f -mtime +7 exec rm -f {} \; |
chown -R user:group $basedir | (
cat <<EOF
Copy of MySQL successfully placed in $basedir directory as file named mysqlbackup.$presentdate.sql.gz.
Now it is ready to be moved to QNAP backup device as scheduled.
EOF
cat
) | /bin/mail -s "Report from scheduled job for mysqldumps" root
My concern is: how can I possibly make it more elegant? Would it be possible to build a function for selecting and renaming files that are older than 7 days? I don't like using find as it produces strange warnings like for example:
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]
that are hard to deal with (at least for me) in such a script.
finddoesn't produce strange warnings if you use it correctlyrm -f), it seems to me there's a dash missing in-exec, right? (backupninjadoes MySQL backups, too.)