[Vserver] Copy VServer

From: Lars Hallberg <lah_at_micropp.se>
Date: Tue 29 Nov 2005 - 18:12:45 GMT
Message-ID: <438C9A1D.2050609@micropp.se>

I'm new to VServer and need a way copy vservers, in short term.
vserver-copy don't work no more and replacment is not done yet? This is
a small script to (on local host only) copy a vserver.

What I wonder before taking it further is.... Have I missed something
important?

------- vservercp --------

# Script to copy a VServer.
#
# Only local copy using rsync -a
# BUG! shuld suport ssh / rsync and remote copy.
#
# Usage:
#
# vservercp from-guestname to-guestname [--force]
#
# Force have to be used to overwrite a target. Only image will be overwriten
# if target exists!
#

parm='from';

# Defaults - can be changes with: --varname="new value"
ssh="ssh" # Command to use for remote shell (not used yet).
copy="rsync -a" # Command to use to copy dirs.
cpconf="1" # Copy config!
confdir="/etc/vservers"
rundir="/var/run/vservers"

for p in "$@"
do
  if [ "${p:0:2}" = "--" ]
  then
      p=${p:2}
      k=${p%%=*}
      if [ "$k" = "$p" ]
      then
          if [ "${k:0:1}" = "!" ]
          then
               eval "${k:1}=\"0\""
          else
               eval "$k=\"1\""
          fi
      else
          eval "$k=\"${p##*=}\""
      fi
  else
      if [ "$parm" = "from" ]
      then
          from="$p"
          parm='to'
      elif [ "$parm" = "to" ]
      then
          to="$p"
          parm='done'
      else
          echo "ERROR To many parameters '$p'"
          exit 1
      fi
  fi
done

if [ -d $confdir/$from ]
then
     source="$confdir/$from/vdir"
else
     echo "Source VServer guest '$from' does not exist"
     exit 1
fi

if [ -d $confdir/$to ]
then
    target="$confdir/$to/vdir"

    if [ "$force" = "1" ]
    then
        echo "Target exist, --force given, only copy image (not conf)!"
        cpconf="0"
    else
        echo "Target exist, --force must be given to overwrite target
image!"
        exit 1
    fi
else
    target="$confdir/.defaults/vdirbase/$to"
fi

$copy $source/. $target

if [ "$cpconf" = "1" ]
then
    $copy $confdir/$from/. $confdir/$to
    cd $confdir/$to
    ln -fs $target vdir
    touch $rundir/$to
    ln -fs $rundir/$to run
fi

_______________________________________________
Vserver mailing list
Vserver@list.linux-vserver.org
http://list.linux-vserver.org/mailman/listinfo/vserver
Received on Tue Nov 29 18:13:59 2005

[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Tue 29 Nov 2005 - 18:14:05 GMT by hypermail 2.1.8