Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyUSER="" # USERNAME
- MyPASS="" # PASSWORD
- MyHOST="localhost" # Hostname
- # Backup Dest directory, change this if you have someother location
- DEST="/backup"
- # Main directory where backup will be stored
- MBD="$DEST/mysql"
- mkdir -p "$MBD"
- # Get hostname
- HOST="$(hostname)"
- # Get data in dd-mm-yyyy format
- NOW="$(date +"%d-%m-%Y")"
- # File to store current backup file
- FILE=""
- # Store list of databases
- DBS=""
- # DO NOT BACKUP these databases
- IGGY="information_schema"
- # Only root can access it!
- chown 0.0 -R "$DEST"
- chmod 0600 "$DEST"
- # Get all database list first
- DBS="$("$MYSQL" -u "$MyUSER" -h "$MyHOST" -p "$MyPASS" -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.$HOST.$NOW.tar"
- # 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 "$MyUSER" -h "$MyHOST" -p "$MyPASS" "$db" | gzip -9 > "$FILE"
- fi
- done
- ########################################################################################
- #This will backup ones home directory to /backup then cp to /mnt/backup and tar it
- #specify the username for the home directory you want to backup
- userName=""
- #user directory to backup
- homeDirectory="/home/$userName"
- #main backup directory
- backupDestination="/backup"
- #backup subdirectory
- subDir="$backupDestination/homeBackup"
- mkdir -p "$subDir"
- #naming convention for files
- fileName="$subDir/$userName.$NOW.tar"
- #tars the file
- gzip -9 "$fileName"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement