Commit 2fcf99c6 authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve vzarchive scripts

parent 5b5b6063
#!/bin/bash #!/bin/bash
SERVER=$1 SERVER=$1
DESTINATION=/var/ftp/pvt/Etersoft/ARCHIVE/vz/$1/$2 VZID=$2
DESTINATION=/var/ftp/pvt/Etersoft/ARCHIVE/vz/${SERVER}/${VZID}
[ $# -ne 2 ] && echo 'Input HOSTNAME and VEID as parameters...' && exit 1 errmsg(){
echo "$@"
exit 1
}
mkdir -p "$DESTINATION" [ $# -ne 2 ] && errmsg "Input HOSTNAME and VEID as parameters..."
ssh ${SERVER} "vzctl stop ${VZID}" &>/dev/null || errmsg "Can't connect to the selected VZ. Check ssh-connection or ID."
if [ -f "$DESTINATION/root_$2.tar.gz" ] mkdir -p "$DESTINATION" || errmsg "Can't create the destination dir."
then [ -f "$DESTINATION/root_${VZID}.tar.gz" ] && errmsg "WARNING ! The destination archive exists... Remove it manually."
echo "WARNING ! The destination archive exists... Remove it manually."
exit 3
fi
ssh $SERVER "tar -czf /tmp/root_$2.tar.gz -C /var/lib/vz/private/ $2" || exit 2 ssh $SERVER "tar -czf /tmp/root_${VZID}.tar.gz -C /var/lib/vz/private/ ${VZID}" || errmsg "Something wrong while tar-archive processing. Check it."
scp $SERVER:/tmp/root_$2.tar.gz "$DESTINATION" && ssh $SERVER "rm -f /tmp/root_$2.tar.gz" scp ${SERVER}:/etc/vz/conf/${VZID}.mount "$DESTINATION"
scp $SERVER:/etc/vz/conf/$2.conf "$DESTINATION" && ssh $SERVER "rm -f /etc/vz/conf/$2.conf" scp ${SERVER}:/etc/vz/conf/${VZID}.umount "$DESTINATION"
scp $SERVER:/etc/vz/conf/$2.mount "$DESTINATION" && ssh $SERVER "rm -f /etc/vz/conf/$2.mount" scp ${SERVER}:/etc/vz/conf/${VZID}.conf "$DESTINATION" && scp $SERVER:/tmp/root_${VZID}.tar.gz "$DESTINATION" && ssh $SERVER "rm -f /tmp/root_${VZID}.tar.gz" && ssh ${SERVER} "vzctl destroy ${VZID}"
scp $SERVER:/etc/vz/conf/$2.umount "$DESTINATION" && ssh $SERVER "rm -f /etc/vz/conf/$2.umount"
#!/bin/bash #!/bin/bash
DESTINATION=/var/ftp/pvt/Etersoft/ARCHIVE/vz/cellar VZID="$1"
mkdir -p "$DESTINATION" DESTINATION=/var/ftp/pvt/Etersoft/ARCHIVE/vz/cellar/${VZID}
[ $# -eq 0 ] && echo 'Input VEID as parameter...' && exit 1 errmsg(){
echo "$@"
exit 1
}
tar -czf root_$1.tar.gz -C /var/lib/vz/private/ $1 || exit 2 [ $# -ne 1 ] && errmsg "Enter VZID as only parameter."
mkdir "$DESTINATION"/$1 vzctl stop ${VZID} &>/dev/null || errmsg "No such ID."
mkdir -p "${DESTINATION}" || errmsg "Can't create the destination folder"
tar -czf root_${VZID}.tar.gz -C /var/lib/vz/private/ ${VZID} || errmsg "Something goes wrong with tar-processing. Check it."
cp -v /etc/vz/conf/${VZID}.mount "${DESTINATION}/"
cp -v /etc/vz/conf/${VZID}.umount "${DESTINATION}/"
cp -v /etc/vz/conf/${VZID}.conf "${DESTINATION}/" && mv -v root_${VZID}.tar.gz "${DESTINATION}/" && vzctl destroy ${VZID}
mv -v root_$1.tar.gz "$DESTINATION"/$1
mv -v /etc/vz/conf/$1.conf "$DESTINATION"/$1/
mv -v /etc/vz/conf/$1.mount "$DESTINATION"/$1/
mv -v /etc/vz/conf/$1.umount "$DESTINATION"/$1/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment