msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

18 Nov 2007 Backup mysql databases into separate files

This bach script makes separate backup files of all the databases in mysql and saves the result in the mysql_backup folder.

#!/bin/bash -v

USERNAME='yourusername'
PASSWORD='yourpassword'
HOSTNAME='yourhostname'
BackupFolder='/backup'

for i in $(echo 'SHOW DATABASES;' | mysql --user $USERNAME -p$PASSWORD -h $HOSTNAME | grep -v '^Database$' ); do
        mysqldump --user $USERNAME -p$PASSWORD -h $HOSTNAME --opt $i > $BackupFolder/$i.sql;
done;

Remember to change the -h, -p and -h switch according to your needs and avoid space between -p and the password variable.

Tags: , , , , ,

Posted by

08 Sep 2007 Script to backup MySql database

#!/bin/bash
# Shell script to backup MySql database
# To backup Nysql databases file to /backup dir and later pick up by your
# script. You can skip few databases from backup too.

MyUSER="SET-MYSQL-USER-NAME"     # USERNAME
MyPASS="SET-PASSWORD"       # PASSWORD
MyHOST="localhost"          # Hostname

# Linux bin paths, change this if it can't be autodetected via which command
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
CHOWN="$(which chown)"
CHMOD="$(which chmod)"
GZIP="$(which gzip)"

# Backup Dest directory, change this if you have someother location
DEST="/backup"

# Main directory where backup will be stored
MBD="$DEST/mysql"

# 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="test"

[ ! -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 $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.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 $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE
    fi
done

Tags: , , , ,

Posted by

09 Jun 2007 Backup harddisk to remote machine

dd bs=1M if=/dev/hda | gzip | ssh user@remote 'dd of=hda.gz'

Tags: , , ,

Posted by

04 Jun 2007 Shell script to backup mySQL database

Shell script to backup MySql database

mysql-backup.bash

#!/bin/bash
# Shell script to backup MySql database
# To backup Nysql databases file to /backup dir and later pick up by your
# script. You can skip few databases from backup too.
# For more info please see (Installation info):
# http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html
# Last updated: Aug - 2005
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2004, 2005 nixCraft project
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------

MyUSER="SET-MYSQL-USER-NAME"     # USERNAME
MyPASS="SET-PASSWORD"       # PASSWORD
MyHOST="localhost"          # Hostname

# Linux bin paths, change this if it can't be autodetected via which command
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
CHOWN="$(which chown)"
CHMOD="$(which chmod)"
GZIP="$(which gzip)"

# Backup Dest directory, change this if you have someother location
DEST="/backup"

# Main directory where backup will be stored
MBD="$DEST/mysql"

# 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="test"

[ ! -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 $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.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 $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE
    fi
done

Tags: , , , ,

Posted by

15 May 2007 Shell scripts for archiving digital photos in directories by month

This is my version of the shell script “Shell scripts for archiving digital photos in directories by date“. It utilizes  the exiftags command available in most linux distributions like Gentoo and debian Linux. Though the metacam program is also usefull since it can read Nikon NEF-files.Here’s an example of a directory tree they create:

2006  2006-10       IMG_48324.JPG       IMG_48325.JPG       IMG_48326.JPG       IMG_48331.JPG       IMG_48333.JPG       IMG_48334.JPG       IMG_48337.JPG  2006-11       IMG_48338.JPG  ...etc...

move-digiphotosThis bash script (move-digifotos) scans EXIF tags from .JPG files in current directory with metacam, creates necessary directories under $BASEDIR and moves the files in them:

#!/bin/bash# Reads EXIF creation date from all .JPG files in the# current directory and moves them carefully under##   $BASEDIR/YYYY/YYYY-MM/YYYY-MM-DD/## ...where 'carefully' means that it does not overwrite# differing files if they already exist and will not delete# the original file if copying fails for some reason.## It DOES overwrite identical files in the destination directory# with the ones in current, however.## This script was originally written and put into# Public Domain by Jarno Elonen ; in June 2003.# Feel free to do whatever you like with it.BASEDIR=/home/backup/testfind -maxdepth 1 -name "*.JPG" | while read x; doDATE=`exiftags "$x" | \   egrep "^[ t]*Image Created:" | \   sed -r "s/Image Created: ([0-9:]*).*/\1/"`if [ ! -z "$DATE" ];then    YEAR=`echo $DATE | sed -r "s/([0-9]*):([0-9]*):([0-9]*)/\\1/"`    MONTH=`echo $DATE | sed -r "s/([0-9]*):([0-9]*):([0-9]*)/\\2/"`    if [ "$YEAR" -gt 0 ] & [ "$MONTH" -gt 0 ]    then    INSTDIR=${BASEDIR}/${YEAR}/${YEAR}-${MONTH}    install -d "$INSTDIR"    INSTFILE="$INSTDIR/$x"    if [ -e "$INSTFILE" ] && ! cmp -s "$x" "$INSTFILE"    then        echo "WARNING: '$INSTFILE' exists already and is different from '$x'."    else        echo "Moving '$x'"        cp -ax "$x" "$INSTFILE"        if ! cmp -s "$x" "$INSTFILE"        then        echo "WARNING: copying failed somehow, will not delete original '$x'"        else        rm -f "$x"        fi    fi    else    echo "WARNING: '$x' doesn't contain date."    fielse    echo "WARNING: '$x' doesn't contain date."fidone

Tags: , , , , , , , , , ,

Posted by