Skip to content

Instantly share code, notes, and snippets.

@frenzymind
Forked from dlage/convert_ploop_to_simfs.sh
Last active November 28, 2023 16:37
Show Gist options
  • Save frenzymind/6af89e805bcd8684b62152af120e9418 to your computer and use it in GitHub Desktop.
Save frenzymind/6af89e805bcd8684b62152af120e9418 to your computer and use it in GitHub Desktop.
Bash script to convert an OpenVZ ploop container back to simfs
#!/bin/sh
####################################################################
# #
# Convert ploop ct to simfs #
# #
# HOW TO USE: #
# ./convert_ploop_to_simfs.sh VEID #
# #
# To use progress2 option rsync version should be 3.1 and higher #
# #
####################################################################
set -e
rsync_options='-aHA --info=progress2 --stats --numeric-ids --delete'
partition='vz'
# Check conditions
verify=`vzlist -H -o status $1`
if [ $verify != 'running' ]; then
echo "Start container first! Aborted."
exit 1
fi
if [ ! -e /etc/vz/conf/$1.conf ]; then
echo "Virtual server configuration file: /etc/vz/conf/$1.conf does not exist."
exit 1
fi
if [ ! -d /$partition/private/$1/root.hdd ]; then
echo "Server does not have a ploop device"
exit 1
fi
if [ ! -d /$partition/private/$1 ]; then
echo "Server does not exist"
exit 1
fi
# Create and mount file system for simfs container
mkdir -p /$partition/private/1000$1/
cp /etc/vz/conf/$1.conf /etc/vz/conf/1000$1.conf
vzctl mount 1000$1
# Rsync files from ploop to simfs
rsync $rsync_options /$partition/root/$1/. /$partition/private/1000$1/
# unmount simfs file system container
vzctl umount 1000$1
# create dump
vzdump 1000$1
# Cleanup
rm -f /etc/vz/conf/1000$1.conf
rmdir /vz/root/1000$1
rm -rf /$partition/private/1000$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment