SVN export script

If you ever wanted to export some svn repository from and clean it from some things like the tests or other helper scripts, i have a nice little helper script.

Download it or copy paste it:

#!/bin/bash

path_export="EXPORTPATH"
remove=( "/export.sh" )


rm -r --force $path_export
svn export . $path_export


for i in "${remove[@]}"
do
    echo $i
    rm -r --force $path_export$i
done

Add any files or directories you want to delete from the exported version to the fourth line like this:

remove=( "export.sh" "another_file.txt" "a_directory" )

Let me know, if you have any suggestions, improvements or if you just like it in the comments.

Little GREPpings

Sometimes it is great to have the little help of grep. I’m often asked for some hints, so here are my favorite tiny commands:

grep -lir 'PATTERN' *

where the l stands for “give me only the file names”, i for “case insensitive”, r for recursive and the asterisk for all files (use *.xml or other wildcards to only search in certain files).

grep -lir 'PATTERN' * | grep -v "svn"

to search all files, except the svn files (hopefully there is no other filename with svn in it 😉 ). The | is the pipe operator.

I hope that they are useful and help you to grep around!

MySQL database backup script

Using the scripts

In another post i wrote two scripts which allow you comfortable to save and restore your disk under ubuntu (other linux probably will work too 😉 ). Now i give you similar scripts for your MySQL databases. I use the plain scripts from the WordPress Backups page and use python 3.1 again for shortness and readability of code.

Again the warning:
Don’t use them mindless, you could damage all your recent work or worse! I don’t take responsibility for the effects of this scripts, you use them on your own response!

You have to give the “db2file.py” a string with a description like this:

./db2file.py 'before installing the newest updates'

and it will create a packed file called:

001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

with an automatic incremented number and the date.

To decompress the file use:

./file2db.py 001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

You can define another database name and user by the -u and -d options, here are the help outputs:

Usage: db2file.py description_string

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name
Usage: file2db.py filename

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Download

You can download them here:
db2file.py
file2db.py

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Ubuntu backup scripts

[toc]

Using the scripts

There are many backup scripts out there for linux. I wrote two on base of a tar with bzip2 and nice (giving you the ability to use your box while [de]compressing by setting the priority of the backups to “lowest”) in python 3.1.

Don’t use them mindless, you could damage all your recent work or worse! I don’t take responsibility for the effects of this scripts, you use them on your own response!

You have to give the “disk2file.py” a string with a description like this:

./disk2file.py 'before installing the newest updates'

and it will create a packed file called:

001__16_5_2011__before_installing_the_newest_updates.tar.bz2

with an automatic incremented number and the date.

To decompress the file use:

./file2disk.py 001__16_5_2011__before_installing_the_newest_updates.tar.bz2

You can define another directory to compress and decompress and a comma separated list of directories to exclude, here are the help outputs:

Usage: disk2file.py description_string

Options:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory=DIRECTORY
                        directory which will be saved (default='/')
  -e EXCLUDE, --exclude=EXCLUDE
                        directories to exclude (separated by comma,
                        default='['/proc', '/lost+found', '/media', '/mnt',
                        '
/sys', '/var/backup*']')
Usage: file2disk.py filename

Options:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory=DIRECTORY
                        directory where the backup will be copied
                        (default='/')

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Download

You can download them here:
disk2file.py
file2disk.py

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.