Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-19 of 19 total

backup subversion repository over email

#!/bin/bash
#
# $Id: repodiff 3 2006-09-21 18:48:39Z sevkin $
#
# subversion repository incremental backup over e-mail
#
# (c) 2006 Vsevolod Balashov under terms of GNU GPL v.2 or later

SVNROOT=/var/svn
EMAIL=your@email.here
STORE=`mktemp -d`
GPGCRYPT=n

for REPO in `ls $SVNROOT`; do 
	REPOPATH=$SVNROOT/$REPO;
	if [ -r $REPOPATH/youngest ]; then
		LATEST=`cat $REPOPATH/youngest`
		YOUNGEST=`svnlook youngest $REPOPATH`
		if [ $LATEST -lt $YOUNGEST ]; then
			svnadmin dump $REPOPATH --incremental -r $LATEST:$YOUNGEST >$STORE/$REPO 2>/dev/null
		fi
	else
		svnadmin dump $REPOPATH --incremental >$STORE/$REPO 2>/dev/null
	fi 
	echo $YOUNGEST >$REPOPATH/youngest 
done

if [ `ls $STORE | wc -w` -gt 0 ]; then
	BACKUP=repodiff_`date -u +%Y%m%d%H%M%S`.tar.bz2
	ATTACH=$STORE/../$BACKUP
	tar  -C $STORE -cjf $ATTACH .
	if [ $GPGCRYPT = y ]; then
		gpg -e -r $EMAIL $ATTACH
		ATTACH=$ATTACH.gpg
	fi
	echo "." | mutt -c $EMAIL -a $ATTACH -s "repository incremental backup"
	rm -f $ATTACH
fi

rm -rf $STORE

MYSQL Backup

// shell script to backu a mysql database

#!/bin/sh

RM=/bin/rm
MV=/bin/mv
TAR=/bin/tar
GZIP=/bin/gzip
CHOWN=/bin/chown

DUMP=/usr/bin/mysqldump

BDIR=/mnt/mrynas/backups/fogbugz

DATE=`date +%Y%m%d`

echo Dumping mysql database as
echo $BDIR/mysql.$DATE.gz
$DUMP --opt -c -e -Q mysql | gzip > $BDIR/mysql.$DATE.gz

Backup Script for Linux

This little shell script qbackup.sh is useful for an automatic backup under Debian Linux. It is based on rsync and requires an usb-storage device (an usb hard disc) to be attached to the machine.


hilfe() {
echo "syntax: qbackup.sh [BACKUP-USER] [BACKUP-DEVICE]"
}

BCKUSR="tweiers";
MNTDEV="/dev/sda7";

for i in $*
do
if [ $i = "-h" -o $i = "-help" -o $i = "--help" -o $i = "-help" ]; then
hilfe;
exit 0
fi
done

if [ $1 ]; then
BCKUSR=$1;
fi

if [ $2 ]; then
MNTDEV=$2;
fi

if [ $USER != "root" ]; then
echo -e "Error: You must be root to run qbackup.sh";
exit 1
fi

mount $MNTDEV /mnt/usb-storage
if [ -d /mnt/usb-storage/$BCKUSR ]; then
rsync -av /home/$BCKUSR/ /mnt/usb-storage/$BCKUSR/;
umount /mnt/usb-storage;
exit 0
else
echo "Error: Could not mount storage device";
exit 2
fi
</code

MySql Backups Under Windows

This batch script will backup any MySql database on the local machine, including all routines (stored procedures and functions), to a file named after the database followed by the date (YYYY-MM-DD) and time (HHMMSSSS). The first argument is the database name, second is the username to run the backup as and third is the password.

This script requires your date and time formats to be the windows default formats. Changing them can break this script. The script pauses at the end to cause a cmd window to remain open for long enough for the user to read the output.

@echo off
echo Starting Backup of Database: %1

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dt=%%c-%%a-%%b)
For /f "tokens=1-4 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b%%c%%d)
set bkupfilename=%1 %dt% %tm%.bak
echo Backing up to file: %bkupfilename%

mysqldump %1 --routines -u %2 -p%3 > "%bkupfilename%"

echo Backup Complete!
pause
echo on


--
Version 0.1.0 - 2006-03-13
STEM: The STEM Cells of PHP
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-sa/2.5/

ssh remote backups

// http://www.linux.com/article.pl?sid=06/01/12/1937210
// Backup with remote compression and storage

// When compression is necessary (and feasible), workload
// distribution becomes more effective with OpenSSH. Just as // distcc allows multiple machines to compile
// simultaneously, OpenSSH lets one system create the
// archive, while another system compresses it:

// tar cf - dirname | ssh remotehost "gzip -c >
// ${TMPFILE}.tar.gz"

tar cf - local-dir-eliotwalker | ssh -l mctt remote-glos.corruptive.co.uk "gzip -c > corr.tar.gz"

Backup MySQL databases into seperate files

A cronable script for backing up all your databases as seperate files. I'd suggest limiting the backup user's access to the IP of the computer backing up, and using some sort of encryption if you're on a capable version of mysql.

#!/bin/sh
#
# MySQL backups from the Data

MOUNTED=`grep /etc/mtab -e \/mnt\/backup`
if [ "$MOUNTED" = '' ]; then
        echo "/mnt/backup is not mounted, there is no drive to backup to"
        exit 1
fi


mkdir -p /mnt/backup/cluster_sql

for i in $(echo 'SHOW DATABASES;' | mysql -ubackup -pSUPERSECRET -hData|grep -v '^Database$'); do
  mysqldump -ubackup -pSUPERSECRET -hData --opt $i > /mnt/backup/cluster_sql/$i.sql;
done;

Making a backup of your del.icio.us bookmarks

wget http://del.icio.us/api/posts/all --http-user=YOURUSERNAME --http-passwd=YOURPASSWORD

Old Ensim backup scripts

backup

#!/bin/sh

echo $1
cd /home/virtual/$1/var/www
tar czfv /home/backups/$1.tar.gz cgi-bin html > /dev/null
chmod 777 /home/backups/$1.tar.gz
echo Backed up $1 to /home/backups/$1.tar.gz


backup-all

#!/bin/sh

rm -f /home/backups/old/*
mv /home/backups/*.gz /home/backups/old/
find -type l -maxdepth 1 -name '*.*' | xargs -n 1 basename | xargs -n 1 ./backup

del.icio.us backup

This ruby script dumps all your del.icio.us bookmarks into a sqlite database. Requires sqlite3-ruby installed via rubygems. Don't forget to change the user and pass.
#!/usr/bin/env ruby
require 'rexml/document'
require 'net/http'
require 'net/https'
require 'rubygems'
require 'sqlite3'

# change credentials!
user = 'username'
pass = 'password'

# User-Agent: required for del.icio.us api
agent = 'del.icio.us backup v0.2'
schema = <<EOF
create table bookmarks (
    hash char(32) primary key,
    url varchar(1024),
    title varchar(1024),
    note varchar(2048),
    time timestamp
);
create table tags (hash char(32), tag varchar(1024));
create index ix_tags_hash on tags (hash);
create index ix_tags_tag on tags (tag);
EOF
insert_url = 'insert into bookmarks (hash, url, title, note, time) ' +
             'values (?, ?, ?, ?, ?);'
insert_tag = 'insert into tags (hash, tag) values (?, ?);'

http = Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
xml = http.start { |http|
    req = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
    req.basic_auth(user, pass)
    http.request(req).body
}

db_name = ARGV[0] || Time.now.strftime("%Y-%m-%d.db")
SQLite3::Database.open(db_name).transaction { |db|
    db.execute_batch(schema)
    db.prepare(insert_url) { |url_stmt|
        db.prepare(insert_tag) { |tag_stmt|
            REXML::Document.new(xml).elements.each('posts/post') { |el|
                url_stmt.execute(el.attributes['hash'],
                    el.attributes['href'], el.attributes['description'],
                    el.attributes['extended'], el.attributes['time'])
                el.attributes['tag'].split(' ').each { |tag|
                    tag_stmt.execute(el.attributes['hash'], tag)
                }
            }
        }
    }
}
« Newer Snippets
Older Snippets »
Showing 11-19 of 19 total