Tools quản trị

Backup Mysql & Webbase by script on Linux

#!/bin/bash
# Database credentials
user=”root”
password=”binhit@1234567890″
host=”localhost”
# Other options
backup_mysql=”/home/backup/mysql”
date=$(date +”%d%m%Y”)
# Show all databases;
db_show=”$(mysql –user=$user –password=$password –host=$host -Bse ‘show databases’)”
for db_name in $db_show
do
# Dump database into SQL file
mysqldump –user=$user –password=$password –host=$host $db_name > $backup_mysql/$db_name-$date.sql
# Delete files older than 30 days
find $backup_mysql/* -mtime +30 -exec rm {} \;
done

# Script backup code directory
backup_code=”/home/backup/code”
html=”/var/www/html”
cd $html
tar -czf “$backup_code/html-$date.tar.gz” *
find $backup_code/* -mtime +30 -exec rm {} \;

Leave a Reply

avatar
  Subscribe  
Notify of