All posts by rohan

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