MySQL DB Backup Script


#!/bin/bash
# Database credentials
user="username"
password="password"
host="localhost"
db_name="dbname"
# Other options
backup_path="/DB/DB_Backup"
date=$(date +"%d-%b-%Y")
# Set default file permissions
umask 177
# Dump database into SQL file
mysqldump --user=$user --password=$password --host=$host $db_name >$backup_path/$db_name-$date.sql

# Delete files older than 30 days
find $backup_path/* -mtime +30 -exec rm {} \;


#DB backup log
echo -e "$(date +'%d-%b-%y  %r '):ALERT:Database has been Backuped"    >>/var/log/DB_Backup.log
Last update:
04-09-2017 10:16
Author:
Karl Hudgell
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Latest FAQs RSS

  1. Simple Cheap LED Control (29-04-2019 13:26)
  2. Freeing disk space on your Linux server (20-04-2019 12:48)
  3. Dockerized Download VM (30-01-2019 20:26)
  4. Jmeter + Performance Plugin + Jenkins Pipeline (16-02-2018 12:49)
  5. MySQL DB Backup Script (04-09-2017 10:16)