Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Minecraftd is also available in the [AUR][aur].
`connect`
: Launch interactive minecraft server stdin prompt.

`backup`
: Create a backup of the server folder

`-H`, `--help`
: Display help and exit.

Expand Down
25 changes: 23 additions & 2 deletions minecraftd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ COMMANDS

connect, con
Launch interactive minecraft server input prompt.

bck, backup
Create a backup of the server folder.
-H, --help
Display help text and exit.

Expand Down Expand Up @@ -54,13 +55,15 @@ flg_cmd=false
flg_con=false
flg_srt=false
flg_stp=false
flg_bck=false
jar='/usr/share/java/minecraft-server.jar'
mem='2g'
mem_srt='1g'
mem_tmp=
reqs=(java)
srv='/srv/minecraft'


## functions ::
error() { msg_error "$@"; exit 5 ;}
msg() { printf "\e[1;38;5;12m=> \e[0;38;5;15m$1\e[0m\n" "${@:2}" ;}
Expand Down Expand Up @@ -103,6 +106,7 @@ case "$1" in
con|connect) flg_con=true ;;
srt|start) flg_srt=true ;;
stp|stop) flg_stp=true ;;
bck|backup) flg_backup=true ;;
-H|--help) print_help; exit 0 ;;
*) error "unknown option: $1" ;;
esac
Expand Down Expand Up @@ -172,7 +176,24 @@ if [ "$flg_con" = true ]; then
done
fi

# TODO: backup command
#create a backup

if [ "$flg_bck" = true ]; then
msg 'Starting backup!'
printf 'save-all' >"$fifo"
sleep 4
printf 'save-off' >"$fifo"
sleep 4
bck="/backups"
if [ ! -d $bck ]; then
mkdir $bck
fi
name="$bck/$(date '+%H_%M_%S_%d_%m_%Y').tar"
tar -cvf $name $srv
gzip $name
printf 'save-on' >"$fifo"
msg 'Backup complete!'
fi

# stop server:
if [ "$flg_stp" = true ]; then
Expand Down