#! /bin/sh -e source=/var/alternc/html target=/srv/alternc/html set -- `getopt vn $*` for i ; do case "$1" in -h) echo "this script aims to ease migration of alternc accounts between disks" echo "it only migrates /var/alternc/html (to /srv/alternc/html) right now" echo "you need to pass the name of the accounts you want to migrate" echo "" echo "example: $0 -v admin" echo "" echo "a symlink is done between /var/alternc/html and /srv/alternc/html" echo "the original directory is renamed but not erased, in case there are bugs in this script..." exit ;; -v) verbose=1 ;; -n) dryrun=1 ;; --) shift break ;; esac shift done for account in $*; do fl=`echo $account | sed 's/^\(.\).*$/\1/'` if ! [ -d $source/$fl/$account ] || [ -h $source/$fl/$account ] ; then echo $account already migrated, skipping continue fi [ $verbose ] && echo "===> syncing account $account" if ! [ -d $target/$fl/$account ] ; then [ $dryrun ] || mkdir -p $target/$fl [ $dryrun ] || (cd $source/$fl && tar cf - $account | pv | ( cd $target/$fl && tar xf - )) fi [ $dryrun ] || mv $source/$fl/$account $source/$fl/$account.old [ $dryrun ] || rsync -a $source/$fl/$account.old/ $target/$fl/$account/ [ $dryrun ] || ln -s $target/$fl/$account $source/$fl/$account [ $verbose ] && echo "$source/$fl/$account.old/ can be destroyed" done