In this tutorial, you will learn how to set up automated backups for your FiveM server using a PowerShell script and Windows Task Scheduler. Automating your backups ensures your server data is safe and can be restored if needed.
Step 1: Download the Backup Script
- Download the backup script from the GitHub opslagplaats.
- Sla de
ServerBackupScript.ps1
file in a location accessible to your server.
Step 2: Set Up Backup Folders
- Create Backup Directory:
- Navigate to your server’s root directory (where the FX Server starter is located).
- Maak een nieuwe map met de naam
backup
.
- Edit the PowerShell Script:
- Open de
ServerBackupScript.ps1
in a text editor (e.g., Notepad). - Werk de
$sourcePath
to the folder you want to back up. For example:$sourcePath = "C:\MyServer\resources"
- Werk de
$destinationPath
to the folder where backups should be stored. For example:$destinationPath = "C:\Backups\ServerBackup_$backupDate"
- De
$backupDate
variable appends the current date and time to the backup folder name for better organization.
- Open de
Step 3: Set Up a Scheduled Task
- Open Task Scheduler:
- Druk op
Win + S
and search for Task Scheduler, then open it.
- Druk op
- Create a New Task:
- Right-click Task Scheduler Library en selecteer Create Basic Task.
- Name the task (e.g., “FiveM Server Backup”) and click Volgende.
- Set the Trigger:
- Choose how often you want the backup to run (e.g., Daily, Weekly).
- Set the start date, time, and frequency as needed, then click Volgende.
- Set the Action:
- Selecteer Start a Program en klik op Volgende.
- In de Program/script field, type:
powershell.exe
- In de Add arguments (optional) field, type:
-File "C:\Backups\ServerBackupScript.ps1"
Adjust the file path if the script is stored elsewhere. - In de Start in (optional) field, type the folder path where the script resides, such as:
C:\Backups
- Finish the Task:
- Klik op Finish to save the task.
Step 4: Test the Task
- Right-click the newly created task in Task Scheduler and select Ren.
- Check the output folder (e.g.,
C:\Backups
) to confirm the backup was created successfully. The backup file or folder should have the current date appended to its name (e.g.,ServerBackup_2024-11-15
).
Step 5: Verify Backup Consistency
- Regularly check your backups to ensure all critical files are included.
- Test restoring a backup on a development server to confirm functionality.
Tips:
- Monitor Backup Size: Keep an eye on disk space in your destination folder.
- Retention Policy: Consider a script to delete older backups automatically if storage space is a concern.
- Logs: Add logging to the PowerShell script for easier debugging.
You have now successfully automated backups for your FiveM server!