Bash

Automated MySQL Backups

The HOWTO will show how to automate the backup of your local MySQL server on a daily basis. The backup process uses a bash script and the local logrotate functionality to achieve an automated systems. The backup is processed daily via cron (see /etc/cron.daily/logrotate).

While this HOWTO is written for a local development environment it could easily by modified for remote multi-server environments.

Step1: Create the backup script

Create a file at /usr/local/sbin/backup_mysql.sh using your favorite text editor. I use joe:

Generate Random Numbers with Bash Scripting

To generate random numbers with bash use the $RANDOM internal Bash function. Note that $RANDOM should not be used to generate an encryption key. $RANDOM is generated by using your current process ID (PID) and the current time/date as defined by the number of seconds elapsed since 1970. The range of returned values is 0 to 32767.

This will return a number between 1 and 100:

NUMBER=$[ ( $RANDOM % 100 )  + 1 ]

Here is a function to dynamically imitate a die:

#!/bin/bash

function roll_die() {

  # capture parameter
  declare -i DIE_SIDES=$1
Syndicate content