Automatic FiveM Server Backup (Standalone)

Automatic server backup powershell script i put together as a scheduled task. Easy way to ensure ALL of your server files are being backed up regularly. You can take it 1 step further and put the files into an FTP drive from the backup destination.

Powershell script to auto backup your FiveM Server.

Create a folder in your main server root (where the FX Server Starter Is) called backup. Edit the powershell script and change the source path to the folder you are backing up, for example: $sourcePath = “C:\MyServer\resources”

Change the destination path to where the backup should be stored: $destinationPath = “C:\Backups\ServerBackup_$backupDate”

The _$backupDate appends the backup time to the file.

Open Windows Task Scheduler> Right Click > Create Basic Task > Name It > Trigger how often you want the backup to run > Action > Start a Program, type powershell.exe In the Add arguments box type -File “path to script”, for example: -File “C:\Backups\ServerBackupScript.ps1”, then for the “start In” box, put the path where the script runs from.

Click ok, then you can right click the new scheduled event and click run, then check your backup output file path and make sure it populates.

5 Likes

this is just for server files right ? database not included

1 Like

Correct, just the files. I can do something else for the DB.

2 Likes

Would be nice

2 Likes

DB would be awesome, I can not find anything good for windows based server

Heidi SQL does not come with a DB extractor by default, but if you install this software:

https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html

Once you have that, this Powershell should work. Just change the parameters:

# Specify the path to mysqldump executable
$mysqldumpPath = "C:\Program Files\MariaDB\MariaDB 10.5\bin\mysqldump.exe"

# Specify the details for connecting to the database
$hostname = "localhost"
$port = 3306
$username = "root"
$password = ""
$database = "esxlegacy_f5298f"

# Specify the path for saving the SQL backup file
$backupPath = "C:\Backups\esxlegacy_f5298f_backup.sql"

# Build the command line arguments for mysqldump
$arguments = "--host=$hostname --port=$port --user=$username --password=$password --databases $database --skip-comments --skip-lock-tables --skip-add-locks --result-file=$backupPath"

# Start mysqldump process with the specified arguments
Start-Process -FilePath $mysqldumpPath -ArgumentList $arguments -NoNewWindow -Wait

:slight_smile: [How to Automatically Backup phpMyAdmin |
(How to Automatically Backup phpMyAdmin | SQLBackupAndFTP's blog)

I use it and retrieve every day my db on Email :wink: