Monthly Archives: June 2011

Find files using forfiles in windows

Few days back I had to accomplish yet another task, finding some files among large data.

The problem was internal windows search function was very slow and it requires indexing (Which we disabled to save resources on server). In linux you can use find command to find the files you are looking for by using following command

find /opt/data -name "*.c"

This will find all the files with c extension under /opt/data directory on Linux. But unfortunately I was on windows and had to improvise. So I remember forfiles utility and used it to find files under D:\data directory on windows using following syntex.

forfiles /P d:\data /M *.c /S /C "cmd /c echo @path

I am sharing this syntex so that it might help somebody.

Please comment your views so that I can also learn a trick or two ;)

Migrating data with robocopy

Few days back I had a situation when I needed to migrate data from one Windows 2003 server to another.

The data contained 2 level of directories and thousands of files in them.

Also the data needed to copied with ACL as well.

so I wrote a script on source server as below to speed up copy.

D:

cd D:\data

For /D %%r in (*) do (

For /D  %%a in (*) do(

cd %%a

start robocopy.exe D:\data\%%r\%%a \\destination\data\%%r\%%a *.* /e /s /w:3 /r:3 /XX /XO /SEC /LOG:c:\robocopy_%%r_%%a.log)

)

I created log file to retain the dir and files list which were copied.

What I did with script is I queried for all directories in D:\data and I again queried the directories under D:\data\DIRECTORIES.

Then I used robocopy utility from Windows server kit to start copying each directories and files at the same time with start command.

If you don’t put start in front of robocopy it will still copy, but it will copy one directory at a time.

Hope this solution will help some other people who may require it.

Please comment suggestions for improvement or what solution you would use to complete this kind of task.

Rsync Backup script

Few days back I had a task to automate backup from one server to another using rsync and I wrote the script as below

#!/bin/sh

# This script does personal backups to a rsync backup server.

# directory to backup
BDIR=/home/$USER

# excludes file - this contains a wildcard pattern per line of files to exclude
EXCLUDES=$HOME/cron/excludes

# the name of the backup machine
BSERVER=Homeserver.org

# your password on the backup server
export RSYNC_PASSWORD=123456

########################################################################

BACKUPDIR=`date +%A`
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
 --delete --backup --backup-dir=/$BACKUPDIR -a"

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

# the following line clears the last weeks incremental directory
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync --delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
rmdir $HOME/emptydir

# now the actual transfer
rsync $OPTS $BDIR $BSERVER::$USER/current