drepk
drepk
AAdmincraft
Created by drepk on 6/30/2023 in #questions
How to make bedrock server (world) backup while server is up?
I run a bedrock server, for backups I've to turn off the server first then copy the files, but it's very unintuitive, I came across the documentation it has three commands basically save hold, save query and save resume. I understand how the commands work, but I'm looking for a Linux script to do this, my bedrock server runs in a separate screen session. I tried writing down the script myself, here's my progress.
#!/bin/bash

# Define variables
SCREEN_NAME="be"
BACKUP_DIR="/home/ec2-user/backups" # Replace with the actual backup directory on your server
S3_BUCKET_NAME="worlds"
TMP_FILE="/home/ec2-user/query_output.txt"

# Function to print logs/errors
print_log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}

# Function to handle errors
handle_error() {
print_log "Error: $1"
exit 1
}

# Enter the screen session and execute backup commands
print_log "running save hold"
screen -S "$SCREEN_NAME" -X stuff "save hold\n"
sleep 1 # Wait for the server to prepare for backup
print_log "running save query"
screen -S "$SCREEN_NAME" -X stuff "save query\n"
sleep 5
screen -S "$SCREEN_NAME" -X hardcopy $TMP_FILE

# Wait for the backup to be ready
while true; do
query_output=$(cat $TMP_FILE)
if [[ $query_output == *"Data saved. Files are now ready to be copied."* ]]; then
file_list=$(echo "$query_output" | grep -oP 'world7/.*?\:\d+')
break
fi
sleep 1
done

print_log "Backup files: $file_list"
# Copy and truncate the backup files
for file in $file_list; do
file_path=$(echo "$file" | cut -d':' -f1)
file_size=$(echo "$file" | cut -d':' -f2)
cp "$file_path" "$BACKUP_DIR/$file_path.tmp" || handle_error "Failed to copy $file_path"
truncate -s "$file_size" "$BACKUP_DIR/$file_path.tmp" || handle_error "Failed to truncate $file_path"
done

# Compress the backup files
...
#!/bin/bash

# Define variables
SCREEN_NAME="be"
BACKUP_DIR="/home/ec2-user/backups" # Replace with the actual backup directory on your server
S3_BUCKET_NAME="worlds"
TMP_FILE="/home/ec2-user/query_output.txt"

# Function to print logs/errors
print_log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}

# Function to handle errors
handle_error() {
print_log "Error: $1"
exit 1
}

# Enter the screen session and execute backup commands
print_log "running save hold"
screen -S "$SCREEN_NAME" -X stuff "save hold\n"
sleep 1 # Wait for the server to prepare for backup
print_log "running save query"
screen -S "$SCREEN_NAME" -X stuff "save query\n"
sleep 5
screen -S "$SCREEN_NAME" -X hardcopy $TMP_FILE

# Wait for the backup to be ready
while true; do
query_output=$(cat $TMP_FILE)
if [[ $query_output == *"Data saved. Files are now ready to be copied."* ]]; then
file_list=$(echo "$query_output" | grep -oP 'world7/.*?\:\d+')
break
fi
sleep 1
done

print_log "Backup files: $file_list"
# Copy and truncate the backup files
for file in $file_list; do
file_path=$(echo "$file" | cut -d':' -f1)
file_size=$(echo "$file" | cut -d':' -f2)
cp "$file_path" "$BACKUP_DIR/$file_path.tmp" || handle_error "Failed to copy $file_path"
truncate -s "$file_size" "$BACKUP_DIR/$file_path.tmp" || handle_error "Failed to truncate $file_path"
done

# Compress the backup files
...
but I can't even copy the read the list of files from the screen, plz help.
9 replies
AAdmincraft
Created by drepk on 6/27/2023 in #questions
How to enable `Beta APIs` in experimental settings, of a bedrock world on dedicated server?
I've a bedrock 1.20 dedicated server running on amazon-Linux, I need to toggle the Beta APIs in the experimental settings. Although I can toggle these settings after I've downloaded the world and load it in Minecraft client as a local world. But I need to change the settings in the server itself. Plz help!!
2 replies