bithead Posted January 7, 2013 Share Posted January 7, 2013 Here is a simple script to keep a max of 5 backups. I will leave it up to you on how to configure for a panel user to fire off the script. The goal is to tell tcadmin to stop the service, perform the backup and then restart the service. At snaju com we use this script to with our Centos-based servers. I have not tested with any other distros. The commands can be further simplified. For instance, tar can also zip - but I wanted to keep the isolated statements to show how this works. #!/bin/bash unalias rm SVCBR="/home/tcadmin/Monitor/servicebrowser" START=" -command=start" STOP=" -command=stop" SVCID=" -service=${Service_ServiceId}" BKUPDIR="./backup" # Steps to perform backup # 1. Stop MC Service eval "$SVCBR $STOP $SVCID" # 2. Compress World NOW=$(date +"%Y-%m-%d-%H-%M-%S") WRLDFILE="world_$NOW.tar" tar cf $WRLDFILE world gzip $WRLDFILE FILESIZE=$(stat -c%s "$WRLDFILE.gz") echo "world zipped = $FILESIZE" # 3. Copy to backup folder mkdir -p $BKUPDIR mv $WRLDFILE.gz $BKUPDIR/. # 4. Start MC Service eval "$SVCBR $START $SVCID" # Now clean up so we only keep the last 5 files ls -F $BKUPDIR/world_* | head -n -5 | xargs rm Link to comment Share on other sites More sharing options...
Bubka3 Posted January 7, 2013 Share Posted January 7, 2013 Thanks for sharing! Link to comment Share on other sites More sharing options...
ECF Posted January 7, 2013 Share Posted January 7, 2013 Thank you for sharing Bithead! Link to comment Share on other sites More sharing options...
LFA Posted January 8, 2013 Share Posted January 8, 2013 Instead of stop/start you can use: -command=write -write=save-off Then after the backup enable auto save again: -command=write -write=save-on That way you create a backup without stopping the service and you don't get corrupt backups by disabling auto save temporarily. Link to comment Share on other sites More sharing options...
bithead Posted January 10, 2013 Author Share Posted January 10, 2013 Thanks for the suggestion. I'm always learning Link to comment Share on other sites More sharing options...
V4Ghost Posted August 31, 2013 Share Posted August 31, 2013 For windows (? Link to comment Share on other sites More sharing options...
frbnet Posted October 6, 2013 Share Posted October 6, 2013 anyone got script converted for ubuntu ?? Link to comment Share on other sites More sharing options...
HFSRyahn Posted February 27, 2014 Share Posted February 27, 2014 Wonderful script. Modified it for my own purpose. anyone got script converted for ubuntu ?? This is bash, ubuntu has it in it. So no need to convert. Link to comment Share on other sites More sharing options...
Winter Posted March 2, 2014 Share Posted March 2, 2014 Any windows testers yes? Link to comment Share on other sites More sharing options...
gaigetech Posted March 13, 2014 Share Posted March 13, 2014 I was working on a script for windows, you reminded me to finish it, if I get it work I'll share it in here. Link to comment Share on other sites More sharing options...
Virtuel-Network Posted March 17, 2014 Share Posted March 17, 2014 (edited) Help me! TCAdmin V2 on linux.. Is my code: #!/bin/bash unalias rm SVCBR="/home/tcadmin/Monitor/servicebrowser" START=" -command=start" STOP=" -command=stop" SVCID=" -service=${Service_ServiceId}" BKUPDIR="${WorkingDirectory}" eval "$SVCBR $STOP $SVCID" NOW=$(date +"%Y-%m-%d-%H-%M-%S") WRLDFILE="world_$NOW.tar" tar cf $WRLDFILE world gzip $WRLDFILE FILESIZE=$(stat -c%s "$WRLDFILE.gz") echo "world zipped = $FILESIZE" mkdir -p $BKUPDIR mv $WRLDFILE.gz $BKUPDIR/. eval "$SVCBR $START $SVCID" ls -f $BKUPDIR/world_* | head -n -5 | xargs rm (Execute as the service's user) Is check Error Log: /home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 2: unalias: rm: not found /home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 9: /home/tcadmin/Monitor/servicebrowser: Permission denied world zipped = 3971062 mkdir: missing operand Try `mkdir --help' for more information. mv: cannot create regular file `/./world_2014-03-17-14-32-34.tar.gz': Permission denied /home/tcagame/_Launcher/Temp/1e1b22f4-72c8-4958-9382-b2cbb285cff7.sh: line 21: /home/tcadmin/Monitor/servicebrowser: Permission denied rm: missing operand Try `rm --help' for more information. The script has executed successfully. You may close this window. Sorry for my bad english Edited March 17, 2014 by Virtuel-Network Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now