Friday, January 8, 2016

Linux(Centos/Ubuntu). Bash history search like in FreeBSD(tcsh)

echo '"\e[A": history-search-backward' >> /etc/inputrc
echo '"\e[B": history-search-forward' >> /etc/inputrc

bind -f /etc/inputrc


You'll find it wonderful! Definitely! It makes search in your bash history really simple. When you type just few first symbols of previously entered command and press arrow keys to get it back and thus avoiding typing of the whole line again and again every time.

Much more fancier than ctrl+r.

Ubuntu. Use vi(vim) within sudo.

ln -sf `which vim` /etc/alternatives/editor

Wednesday, January 6, 2016

Daily backups of all mysql databases (shell script with a fancy date format and retention period)

#!/bin/sh

BACKUP_DIR="/mnt/nfs_backup/backups/mysqldumps"

# Keep daily and ad-hoc backups separately
mkdir -p $BACKUP_DIR/daily
mkdir -p $BACKUP_DIR/longterm

# Perform backup of all databases
# --single-transaction option is used to make "consistent state of the database at the time when START TRANSACTION was issued without blocking any applications."
# --events option is used to avoid warnings (being sent via email from cron). It's for "Event Scheduler events for the dumped databases"
mysqldump --single-transaction --all-databases --events | gzip -9 > $BACKUP_DIR/daily/mysqldump_alldatabases_`date +"%Y%m%d_%H%M%S"`.sql.gz

# Keep daily backups for 20 days
find $BACKUP_DIR/daily -mtime +20 -type f -name "*sql.gz" -exec /bin/rm -rf {} \;