Skip to content

Instantly share code, notes, and snippets.

@danilogco
Last active January 22, 2025 13:04
Show Gist options
  • Save danilogco/7d1a1ddecc70e1fb63ae179738373704 to your computer and use it in GitHub Desktop.
Save danilogco/7d1a1ddecc70e1fb63ae179738373704 to your computer and use it in GitHub Desktop.
Palworld dedicated server backup script - Ubuntu Server
# crontab -e
# 0 3 * * * /home/steam/backup.sh
# 30 3 * * * /home/steam/clean.sh
# 0 4 * * * /sbin/shutdown -r now
#!/bin/bash
# Caminho para o diretório de saves do Palworld
SAVE_DIR="/home/steam/.steam/steam/steamapps/common/PalServer/Pal/Saved"
# Nome do bucket S3
BUCKET_NAME="palworld-saves-backup"
# Data e hora para nomear o arquivo
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
# Nome do arquivo de backup
BACKUP_FILE="palworld_saves_$DATE.tar.gz"
# Criar o arquivo de backup
tar -czvf $BACKUP_FILE -C $SAVE_DIR .
# Enviar para o S3
aws s3 cp $BACKUP_FILE s3://$BUCKET_NAME/backups/
# Remover o arquivo local após o upload
rm $BACKUP_FILE
# Listar os backups no S3, ordenar pela data e manter somente os 10 mais recentes
BACKUPS=$(aws s3 ls s3://$BUCKET_NAME/backups/ --recursive | sort | head -n -10 | awk '{print $4}')
# Excluir os backups antigos
for FILE in $BACKUPS; do
if [ -n "$FILE" ]; then
aws s3 rm s3://$BUCKET_NAME/$FILE
fi
done
echo "Backup concluído e antigos backups excluídos com sucesso."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment