default sync by torrent, rsync with option -d
This commit is contained in:
parent
962cfa69d6
commit
406b79bec4
1 changed files with 44 additions and 17 deletions
|
@ -4,26 +4,35 @@ set -eu
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat << EOF >&2
|
cat << EOF >&2
|
||||||
Usage: $(basename "$0") [-d vmname] [-a] [-t]"
|
Usage: $(basename "$0") [-d] [-a] [-t] [vmnames]"
|
||||||
The images from images.list and xml-directory will be synced from server.
|
Images from vmnames-List will be synced from server. Default by torrent.
|
||||||
|
Using flag -d VMs will be synced by rsync
|
||||||
|
Using flag -a images from images.list and xml-directory will be synced from server.
|
||||||
Using flag -t all torrents and xml-VM-Definitions will be synced
|
Using flag -t all torrents and xml-VM-Definitions will be synced
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_DIR="/tmp/${SUDO_UID}/vmimages"
|
|
||||||
|
|
||||||
download_image() {
|
download_image() {
|
||||||
|
rsync -av --password-file=/etc/rsync.secret \
|
||||||
|
"rsync://vmuser@server:/vmimages-download/${VM_NAME}.qcow2" \
|
||||||
|
/var/lib/libvirt/images/
|
||||||
|
rsync -av --password-file=/etc/rsync.secret \
|
||||||
|
"rsync://vmuser@server:/vmimages-download/xml/${VM_NAME}.xml" \
|
||||||
|
/var/lib/libvirt/images/xml/
|
||||||
|
rsync -av --password-file=/etc/rsync.secret \
|
||||||
|
"rsync://vmuser@server:/vmimages-download/${VM_NAME}.qcow2.torrent" \
|
||||||
|
/var/lib/libvirt/images/
|
||||||
|
/usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2"
|
||||||
|
}
|
||||||
|
|
||||||
|
torrent_image() {
|
||||||
if [[ -f "/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" ]]; then
|
if [[ -f "/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" ]]; then
|
||||||
cd /var/lib/libvirt/images
|
cd /var/lib/libvirt/images
|
||||||
ctorrent -e 0 "${VM_NAME}.qcow2.torrent"
|
ctorrent -e 0 "${VM_NAME}.qcow2.torrent"
|
||||||
/usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2"
|
/usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2"
|
||||||
else
|
else
|
||||||
rsync -av --password-file=/etc/rsync.secret \
|
echo "No torrent-File found"
|
||||||
"rsync://vmuser@server:/vmimages-download/${VM_NAME}.qcow2" \
|
exit 1
|
||||||
/var/lib/libvirt/images/
|
|
||||||
rsync -av --password-file=/etc/rsync.secret \
|
|
||||||
"rsync://vmuser@server:/vmimages-download/xml/${VM_NAME}.xml" \
|
|
||||||
/var/lib/libvirt/images/xml/
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,21 +50,39 @@ sync_all_torrents() {
|
||||||
/var/lib/libvirt/images/
|
/var/lib/libvirt/images/
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ':d:at' OPTION; do
|
while getopts ':dat' OPTION; do
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
d)
|
d)
|
||||||
VM_NAME=$OPTARG
|
DOWNLOAD=1
|
||||||
download_image
|
|
||||||
;;
|
;;
|
||||||
a)
|
a)
|
||||||
sync_all_images
|
sync_all_images
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
t)
|
t)
|
||||||
sync_all_torrents
|
sync_all_torrents
|
||||||
;;
|
;;
|
||||||
?)
|
?)
|
||||||
show_help
|
show_help
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
shift "$((OPTIND -1))"
|
||||||
|
|
||||||
|
# if less than one arguments supplied, display usage
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for VM_NAME in "$@"; do
|
||||||
|
if [[ -v "DOWNLOAD" ]]; then
|
||||||
|
echo "Downloading $VM_NAME"
|
||||||
|
download_image
|
||||||
|
else
|
||||||
|
echo "Torrenting $VM_NAME"
|
||||||
|
torrent_image
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
Loading…
Add table
Reference in a new issue