Skip to content

Instantly share code, notes, and snippets.

@tobidsn
Created September 24, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobidsn/1abe9e75095a67f194c1cf6c00aac141 to your computer and use it in GitHub Desktop.
Save tobidsn/1abe9e75095a67f194c1cf6c00aac141 to your computer and use it in GitHub Desktop.
Backup MySQL to Amazon S3 Specific Table
#!/bin/bash
# Based on https://gist.github.com/2206527
# Be pretty
echo -e " "
echo -e " . ____ . ______________________________"
echo -e " |/ \| | |"
echo -e "[| \e[1;31m♥ ♥\e[00m |] | S3 MySQL Backup Script v.0.1 |"
echo -e " |___==___| / © oodavid 2012 |"
echo -e " |______________________________|"
echo -e " "
# Basic variables
mysqlpass="ROOT"
bucket="s3://bucketname"
# database name
db="database"
# Timestamp (sortable AND readable)
bulan=`date +"%A %d %B %Y"`
stamp=`date +"%s - %A %d %B %Y @ %H%M"`
# Feedback
echo -e "Dumping to \e[1;32m$bucket/$stamp/\e[00m"
# Define our filenames
filename="$stamp - $db.sql.gz"
tmpfile="/tmp/$filename"
object="$bucket/$bulan/$stamp/$filename"
# Feedback
echo -e "\e[1;34m$db\e[00m"
# Dump and zip
echo -e " creating \e[0;35m$tmpfile\e[00m"
mysqldump -u root -p$mysqlpass --force --opt "$db" [table] [table] | gzip -c > "$tmpfile"
# Upload
echo -e " uploading..."
s3cmd put "$tmpfile" "$object"
# Delete
rm -f "$tmpfile"
# Jobs a goodun
echo -e "\e[1;32mJobs a goodun\e[00m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment