Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #################################################################
- # Edit the Following #
- #################################################################
- sql_user="root"
- sql_pass="7gatu9KAopen"
- sql_host="localhost"
- # Files you want to backup
- backup_files="/home /var/vmail /var/www"
- #################################################################
- # Do NOT Touch #
- #################################################################
- # Linux bin paths, change this if it can not be autodetected via which command
- MYSQL="$(which mysql)"
- MYSQLDUMP="$(which mysqldump)"
- CHOWN="$(which chown)"
- CHMOD="$(which chmod)"
- GZIP="$(which gzip)"
- # Get data in dd-mm-yyyy format
- NOW="$(date +"%d-%m-%Y")"
- # Backup Dest directory, change this if you have someother location
- DEST="/backup/$NOW"
- # Main directory where backup will be stored
- MBD="$DEST/mysql"
- # File to store current backup file
- FILE=""
- # Store list of databases
- DBS=""
- # DO NOT BACKUP these databases
- IGGY=""
- [ ! -d $MBD ] && mkdir -p $MBD || :
- # Only root can access it!
- $CHOWN 0.0 -R $DEST
- $CHMOD 0600 $DEST
- # Get all database list first
- DBS="$($MYSQL -u $sql_user -h $sql_host -p$sql_pass -Bse 'show databases')"
- for db in $DBS
- do
- skipdb=-1
- if [ "$IGGY" != "" ];
- then
- for i in $IGGY
- do
- [ "$db" == "$i" ] && skipdb=1 || :
- done
- fi
- if [ "$skipdb" == "-1" ] ; then
- FILE="$MBD/$db.gz"
- # do all inone job in pipe,
- # connect to mysql using mysqldump for select mysql database
- # and pipe it out to gz file in backup dir :)
- $MYSQLDUMP -u $sql_user -h $sql_host -p$sql_pass $db | $GZIP -9 > $FILE
- fi
- done
- # Create archive filename.
- archive_file="backup.tgz"
- # Print start status message.
- echo "Backing up $backup_files to $DEST/$archive_file"
- date
- echo
- # Backup the files using tar.
- tar czf $DEST/$archive_file $backup_files
- # Print end status message.
- echo
- echo "Backup finished"
- date
- # Long listing of files in $DEST to check file sizes.
- ls -lh $DEST
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement