Create a gist now

Instantly share code, notes, and snippets.

IMUNES - Scripts to export data changed while running an experiment, and load them back
#!/bin/bash
ExperimentToLoad=$(docker ps | grep "imunes" | awk '{print $NF}' | cut -d . -f 1 | sort | uniq | awk 'NR==1{print "TRUE\n"$0} NR>1{print "FALSE\n"$0}'\
| zenity --list --radiolist --separator='\n' --title="Seleziona l'esperimento nel quale caricare i dati" --column="" --column="Nome" --text="Seleziona l'esperimento nel quale caricare i dati")
if [ -z "$ExperimentToLoad" ]; then
zenity --error --text "Esperimento non selezionato" --title "Errore"
exit;
fi
ExperimentContainers=$(docker ps | grep $ExperimentToLoad | awk '{print $NF}')
if [ -z "$ExperimentContainers" ]; then
zenity --error --text "Impossibile fare il retrieve dei container" --title "Errore"
exit;
fi
zenity --question --text="Sono stati trovati i seguenti container: $ExperimentContainers. Proseguire?"
DirectoryToLoadFrom=$(echo $(zenity --file-selection --directory --title="Scegli una directory"))
if [ -z "$DirectoryToLoadFrom" ]; then
zenity --error --text "Directory non specificata" --title "Errore"
exit;
fi
expname=$(basename $DirectoryToLoadFrom | cut -d _ -f 1)
containersThatHaveFolder=""
for container in $ExperimentContainers; do
containerSymbol=$(echo $container | cut -d . -f 2)
DirToCheck=${DirectoryToLoadFrom}"/"${expname}.${containerSymbol}
if [ -d $DirToCheck ]; then
containersThatHaveFolder=${containersThatHaveFolder}" "${containerSymbol}
fi
unset containerSymbol
unset DirToCheck
done
containersThatHaveFolderTrimmed="$(echo -e "${containersThatHaveFolder}" | sed -e 's/[[:space:]]*$//')"
if [ -z "$containersThatHaveFolderTrimmed" ]; then
zenity --error --text "Non ho trovato dati relativi a questa topologia nella cartella. Se sei convinto di aver selezionato la cartella giusta, rimetti i file a mano con il comando hcp"
else
for container in $containersThatHaveFolderTrimmed; do
echo "Restoring data in ${expname}.${container}"
for file in $(ls "${DirectoryToLoadFrom}/${expname}.${container}"); do
echo docker cp "${DirectoryToLoadFrom}/${expname}.${container}/${file}" ${expname}.${container}:/
done
echo "Restored data for ${expname}.${container}"
done
zenity --info --text "Caricamento dei container $containersThatHaveFolderTrimmed completato" --title "Caricamento completato"
fi
#!/bin/bash
ExperimentToLoad=$(docker ps | grep "imunes" | awk '{print $NF}' | cut -d . -f 1 | sort | uniq | awk 'NR==1{print "TRUE\n"$0} NR>1{print "FALSE\n"$0}'\
| zenity --list --radiolist --separator='\n' --title="Seleziona l'esperimento nel quale caricare i dati" --column="" --column="Nome" --text="Seleziona l'esperimento nel quale caricare i dati")
if [ -z "$ExperimentToLoad" ]; then
zenity --error --text "Esperimento non selezionato" --title "Errore"
exit;
fi
ExperimentContainers=$(docker ps | grep $ExperimentToLoad | awk '{print $NF}')
if [ -z "$ExperimentContainers" ]; then
zenity --error --text "Impossibile fare il retrieve dei container" --title "Errore"
exit;
fi
zenity --question --text="Sono stati trovati i seguenti container: $ExperimentContainers. Proseguire?"
DirectoryToLoadFrom=$(echo $(zenity --file-selection --directory --title="Scegli una directory"))
if [ -z "$DirectoryToLoadFrom" ]; then
zenity --error --text "Directory non specificata" --title "Errore"
exit;
fi
expname=$(basename $DirectoryToLoadFrom | cut -d _ -f 1)
containersThatHaveFolder=""
for container in $ExperimentContainers; do
containerSymbol=$(echo $container | cut -d . -f 2)
DirToCheck=${DirectoryToLoadFrom}"/"${expname}.${containerSymbol}
if [ -d $DirToCheck ]; then
containersThatHaveFolder=${containersThatHaveFolder}" "${containerSymbol}
fi
unset containerSymbol
unset DirToCheck
done
containersThatHaveFolderTrimmed="$(echo -e "${containersThatHaveFolder}" | sed -e 's/[[:space:]]*$//')"
if [ -z "$containersThatHaveFolderTrimmed" ]; then
zenity --error --text "Non ho trovato dati relativi a questa topologia nella cartella. Se sei convinto di aver selezionato la cartella giusta, rimetti i file a mano con il comando hcp"
else
for container in $containersThatHaveFolderTrimmed; do
echo "Restoring data in ${expname}.${container}"
for file in $(ls "${DirectoryToLoadFrom}/${expname}.${container}"); do
echo docker cp "${DirectoryToLoadFrom}/${expname}.${container}/${file}" ${expname}.${container}:/
done
echo "Restored data for ${expname}.${container}"
done
zenity --info --text "Caricamento dei container $containersThatHaveFolderTrimmed completato" --title "Caricamento completato"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment