Created
August 3, 2018 04:41
-
-
Save Caellian/62fe4169fb9e38393baab30e57c8f51e to your computer and use it in GitHub Desktop.
Backup & Restore scripts - arch, partclone, zstd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "$EUID" -ne 0 ] | |
then | |
echo -e "\033[0;33mWARNING:\033[0m This script requires root privileges!" | |
fi | |
if [ $# -ne 2 ] | |
then | |
echo -e "\033[0;31mERROR:\033[0m Image name and/or drive not given in arguments!" | |
echo "Usage:" | |
echo -e "\t\033[1;31mbackup <image name> <drive>\033[0m" | |
exit | |
fi | |
if mount | grep -iq "$2" | |
then | |
echo -e "\033[1;34m$2\033[0m is mounted!" | |
echo -en "Would you like to unmount it \033[0;32m(y/n)\033[0m? " | |
read answer | |
if echo "$answer" | grep -iq "^y" | |
then | |
sudo umount $2 | |
else | |
echo "Exiting..." | |
exit | |
fi | |
fi | |
if [ -f "$1.pcl.zst" ] | |
then | |
echo -e "File \033[1;34m$1.pcl.zst\033[0m already exists!" | |
echo -en "Do you want to delete it \033[0;32m(y/n)\033[0m? " | |
read answer | |
if echo "$answer" | grep -iq "^y" | |
then | |
sudo rm "$1.pcl.zst" | |
else | |
echo "Exiting..." | |
exit | |
fi | |
fi | |
FSTYPE=$(sudo blkid | grep $2 | grep -oP "(?<=\sTYPE=\")\w+(?=\")") | |
sudo partclone.$FSTYPE -c -s $2 | zstd -19 -T4 -f -o "$1.pcl.zst" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "$EUID" -ne 0 ] | |
then | |
echo -e "\033[0;33mWARNING:\033[0m This script requires root privileges!" | |
fi | |
if [ $# -ne 2 ] | |
then | |
echo -e "\033[0;31mERROR:\033[0m Source image and/or drive not given in arguments!" | |
echo "Usage:" | |
echo -e "\t\033[1;31mrestore <image> <drive>\033[0m" | |
exit 1 | |
fi | |
if mount | grep -iq "$2" | |
then | |
echo -e "\033[1;34m$2\033[0m is mounted!" | |
echo -en "Would you like to unmount it \033[0;32m(y/n)\033[0m? " | |
read answer | |
if echo "$answer" | grep -iq "^y" | |
then | |
sudo umount $2 | |
else | |
echo "Exiting..." | |
exit 0 | |
fi | |
fi | |
echo -en "Your data will be lost! Would you like to continue \033[0;32m(y/n)\033[0m? " | |
read answer | |
if echo "$answer" | grep -iq "^y" | |
then | |
sudo cat $1 | zstdcat | partclone.restore -C -O $2 | |
else | |
echo "Exiting..." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment