Databases Linux mysql: backups bash cron data MySQL mysqldump scripting shell
by bseanvt
leave a comment
Backup and Rotate MySQL Databases Simple Bash Script
Make a directory ( it can anywhere ) called baks/mysql
mkdir -p /baks/mysql
Create a file (it can be anywhere) called /root/mysql_backups.sh and put this script in it
#!/bin/bash # modify the following to suit your environment export DB_BACKUP="/baks/mysql" export DB_USER="root" export DB_PASSWD="your-mysql-password-goes-here" # title and version echo "" echo "Backup and rotate all mysql databases" echo "--------------------------" rm -rf $DB_BACKUP/04 mv $DB_BACKUP/03 $DB_BACKUP/04 mv $DB_BACKUP/02 $DB_BACKUP/03 mv $DB_BACKUP/01 $DB_BACKUP/02 mkdir $DB_BACKUP/01 echo "* Creating backup..." mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2 echo "----------------------" echo "Done" exit 0
Install it via cron and have it run at 3:10 am every morning.
crontab -e 10 3 * * * /root/mysql_backups.sh > /baks/status.log
This script will save the last 4 days of data.
bash environment Linux: bash configuration development environment named pipe pipes tmux
by bseanvt
2 comments
How to Copy and Paste to/from the Global Register with Tmux on Mac OS X
Using the system clipboard with tmux on OS X is broken. I really like tmux but having copy and paste is kind of important for me. Here is my attempt to get it back with a simple bash script until I find something better. The approach is to take a named pipe and feed it the contents of “tmux showb”. A bash script will manage the pipe and because this script is initialized from a normal session it will write to the system clipboard just fine.
In my .bash_profile…
pipe4tmux=/tmp/pipe4tmux alias tcp="tmux showb > $pipe4tmux" if [[ ! -p $pipe4tmux ]]; then ~/pipe4tmux.sh & fi
And in pipe4tmux.sh…
#!/bin/bash pipe4tmux=/tmp/pipe4tmux echo "Starting named pipe $pipe4tmux" trap "rm -f $pipe4tmux" EXIT if [[ ! -p $pipe4tmux ]]; then mkfifo $pipe4tmux fi while true do pbcopy < $pipe4tmux done echo "Quitting pipe4tmux $pip4tmux"
Updating Your Twitter Status with cURL and a Bash Function
I’m usually at the command line so I wrote a little a bash function so that i can type
tweet this is really neat but kind of pointless
and it will update my twitter status! some characters trip it up but in general it’s useful for most of my tweets. The tweet function just spits out the arguments passed to it for the status parameter for the API call to twitter.
Add the following to the .bash_profile file and reload the terminal (don’t forget to add your email and pwd where appropriate).
tweet() {
curl -u your_twitter_email_addr:your_twitter_passwd -d status="$*" http://twitter.com/statuses/update.xml
}
*** Twitter still uses http basic authentication for their API. However, they are moving away from it in favor of oAuth. So I’m not sure how long this fun will last :{


