Skip to content

Instantly share code, notes, and snippets.

@tassaron

tassaron/backup-mc.sh

Last active Jan 25, 2021
Embed
What would you like to do?
SSH copy and unzip the latest Bedrock Dedicated Server backup created by TapeWerm's MCscripts
# Install unzip. Put your IP on next line. Voila!
IP=
PORT=22
BACKUP_DIR=~/MCbackups
if [ -z $IP ]; then
echo "Edit server ip into $0"
exit
fi
ls "$BACKUP_DIR" > /dev/null 2>&1
if [ $? != 0 ]; then
mkdir "$BACKUP_DIR"
if [ $? != 0 ]; then
echo "Couldnt create $BACKUP_DIR"
exit
fi
fi
abort_if_failed() {
if [ $? != 0 ]; then
echo "Previous command failed. Aborting"
exit
fi
}
year=$(date +"%Y")
month=$(date +"%b")
day=$(date +"%d")
scp -P $PORT -r $IP:/opt/MC/backup_dir/bedrock/MCBE_Backups/FriendWorld_Backups/$year/$month/"$day"_04-05.zip /tmp/.
abort_if_failed
dir="$BACKUP_DIR"/$(date +"%Y-%m-%d")
newdir="$dir"
iter=0
ls "$dir" > /dev/null 2>&1
while [ $? == 0 ]; do
let iter=$iter+1
newdir="$dir"-$iter
ls "$newdir" > /dev/null 2>&1
done
mkdir "$newdir"
abort_if_failed
unzip /tmp/"$day"_04-05.zip -d "$newdir"/$year-$month-$day/
abort_if_failed
rm /tmp/"$day"_04-05.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment