Skip to content

Instantly share code, notes, and snippets.

@OstlerDev
Last active August 29, 2015 14:25
Show Gist options
  • Save OstlerDev/2ff2cbaf610bbd540ea9 to your computer and use it in GitHub Desktop.
Save OstlerDev/2ff2cbaf610bbd540ea9 to your computer and use it in GitHub Desktop.
Minecraft Auto-backup
#!/bin/bash
# ftp login info
HOST='example.com'
USER="username"
PASSWD="password"
# cd into the world folder in order to get the name of the latest file.
cd /opt/msm/archives/worlds/tulpa/world/
FILE="$(ls -lat | head -3 | tail -1 | awk '{print $9}')"
# set the remote path for the FTP upload
REMOTEPATH='/mc-backup/'
# move the files around and rename them
echo "Moving zips around"
cd ..
mv world/*.zip world.zip
mv world_nether/*.zip world_nether.zip
mv world_the_end/*.zip world_the_end.zip
# remove folders
echo "Deleting folders"
rm -rf world/
rm -rf world_nether/
rm -rf world_the_end/
# unzip the files
echo "Unziping files and moving them into the directory."
# extract the main world
unzip world.zip -d .
# rename the main world to tulpa
mv world tulpa
# extract the nether
unzip world_nether.zip -d .
# rename world_nether to nether
mv world_nether nether
# copy the villages_nether.dat file manually as spigot stores it in the main data folder
cp world/data/villages_nether.dat nether/DIM-1/data/villages_nether.dat
# Move the folder into the correct place.
mv nether/DIM-1/ tulpa/DIM-1/
# Unzip the end
unzip world_the_end.zip -d .
# rename world_the_end to end
mv world_the_end end
# Copy the villages_end.dat file manually.
cp world/data/villages_end.dat end/DIM1/data/villages_end.dat
# Move the end into the correct place.
mv end/DIM1/ tulpa/DIM1/
# zip all the worlds.
echo "Ziping world"
zip -r $FILE tulpa/
# Once the zip finishes upload that new zip file.
echo "Uploading world backup"
ftp -p -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $REMOTEPATH
bin
put $FILE
quit
END_SCRIPT
echo "Backup Uploaded"
# Delete all files in that directory.
echo "Cleaning up..."
rm world.zip
rm world_nether.zip
rm world_the_end.zip
rm $FILE
rm -rf tulpa/
rm -rf nether/
rm -rf end/
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment