> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/other/backup-bacula/how-tos/bacula-for-windows.md).

# Bacula for Windows

***

Below are the instructions for installing and configuring Bacula for use with our system.

First, you need to log in to your server as the Administrator user or a user with equivalent privileges.

1. Download and install the latest Bacula version from [here](http://sourceforge.net/projects/bacula/files/Win32_64/5.2.10/).
2. Create the folder `C:\TEMP`.
3. Locate and open `bacula-fd.conf`. The file should appear as ***Edit Client Configuration*** in Bacula’s Start menu folder.
4. Replace the entire contents of `bacula-fd.conf` with the following.

If your server is placed in Stockholm:

{% code title="bacula-fd.conf" %}

```
Director {
  Name = bacula01-fbg-dir
  Password = YourPasswordGoesHere
}

FileDaemon {
  Name = ds****-fd
  FDport = 9102
  FDAddress = 0.0.0.0
  WorkingDirectory = C:/TEMP
  Pid Directory = C:/TEMP
  Maximum Concurrent Jobs = 20
}

Director {
  Name = bacula01-fbg-mon
  Password = "4CbWhjnxrVUuRA0ZSljhByGPJtaoyPTVF"
  Monitor = yes
}

Messages {
  Name = Standard
  director = bacula01-fbg-dir = all, !skipped
}
```

{% endcode %}

If your server is placed in Falkenberg:

{% code title="bacula-fd.conf" %}

```
Director {
  Name = bacula03-vbdc-dir
  Password = YourPasswordGoesHere
}

FileDaemon {
  Name = ds****-fd
  FDport = 9102
  FDAddress = 0.0.0.0
  WorkingDirectory = C:/TEMP
  Pid Directory = C:/TEMP
  Maximum Concurrent Jobs = 20
}

Director {
  Name = bacula03-vbdc-mon
  Password = "-Uqm36DICZsRgHje12wxxo1JwRd75hyzF"
  Monitor = yes
}

Messages {
  Name = Standard
  director = bacula03-vbdc-dir = all, !skipped
}
```

{% endcode %}

Replace `YourPasswordGoesHere` with a password you choose. Also, change `ds****-fd` to your server’s name, e.g., `ds1234-fd`.

5. Restart the Bacula service.
6. Add firewall rules for Bacula. Bacula needs to allow incoming traffic on port 9102 and outgoing traffic on port 9103.

Send a message to <support@glesys.se> containing the new password and a list of the directories you want to back up. Preferably in the format shown below:

{% code title="Example format for email" %}

```
bacula::config { "ServerName":
 client => "ServerName",
 address => 'IpAddress',
 password => 'Password',
 files => ['C:/Backup/', 'F:/Internt/'],
 storage => 20, #utrymme för de filer som ska ha backup x4
 email => 'kund@mail.toppdomän',
 excludes => ['C:/Backup/mapp1', 'F:/Internt/mapp2'], #om man inte ska ta backup på undermappar
 }
```

{% endcode %}

## Bacula and MSSQL

Backups with Bacula operate at the file level and read data directly from disk. For MSSQL, it isn’t always guaranteed that all data has been flushed to disk, and restoring the raw SQL data files doesn’t always work. Therefore, we recommend dumping the database to .bak files at regular intervals.

Below, we show an example of how you can schedule a database dump.

Create a file—or use PowerShell ISE—with the following content and save it as `backup‑script.ps1`.

{% code title="backup‑script.ps1" %}

```powershell
#Backup-MSSQL-Database
#module needed for Powershell to "talk" to SQL
Import-Module “sqlps” -DisableNameChecking

$backupdir = "C:\backup"
$date = get-date -format dd-MM-yyyy

# Create MSSQL-backup folder if not existing
$tmpDir = Test-Path $backupdir\MSSQL\
If ($tmpDir -eq $True) {}
Else {
    New-Item $backupdir\MSSQL\ -type directory -force |Out-Null
}

#Deletes everything in the folder (This is needed before the backup because it will otherwise merge with the files that's already there.)
Get-ChildItem $backupdir\MSSQL\ -Recurse | Remove-Item -Force -Recurse

# Check the name of the instance
$checkinstance = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
if ($checkinstance -match "MSSQLSERVER") {
    $instancename = "DEFAULT"
    }
Else {
    $instancename = $checkinstance
}

# Go to the database location
$computername = Get-ChildItem SQLSERVER:\SQL\
$machinename = $computername.MachineName

# Start the backup
# If the script can't find the location of to the database, run PowerShell with "SQLPS" enabled and type "SQLPS". Traverse the SQL directory until you get to the folder Databases.
# Change the Set-Location to match your new location.
$Error.clear()
Set-location SQLSERVER:\sql\$machinename\$instancename\Databases
Write-Host -Foregroundcolor White " -> [INFO] Starting MSSQL backup"
foreach($database in (Get-ChildItem)) {
  $dbName = $database.Name
  Backup-SqlDatabase -Database $dbName -BackupFile $backupdir\MSSQL\$dbName-$date.bak -BackupAction Database }

  if ($Error -ne $null) {
  Write-Host -Foregroundcolor Red " -> [CRITICAL] Could not complete the MSSQL backup"
  Wait-Event -Timeout 5
  Exit
  }
  Else {
    Write-Host -Foregroundcolor Green " -> [OK] MSSQL backup completed successfully"
}

# If you are using the Standard Version of MSSQL server you can add "-Compression on" like so, to compress the backup.
# Backup-SqlDatabase -Database $dbName -BackupFile $backupdir\MSSQL\$dbName-$date.bak -BackupAction Database -Compression on }

```

{% endcode %}

### How the script works

Note that this script is intended for MSSQL installations where the local administrator account has access to the database.

The first thing the script does is import the MSSQL module into PowerShell (if the module is not installed, the script will not work).

Next, it checks whether the folder `C:\backup\MSSQL` exists; if it does not, the script creates the directory.

Now onto something a bit more advanced. The script tries to determine the path to your database, but it doesn’t always succeed. This depends on how the installation was performed and which version of MSSQL is running.

If it fails, the script includes instructions on how to set the database path manually.

Once that’s done, it will locate your databases and dump them into separate  `.bak` files.

The script could be scheduled with the following instruction to save the database to a file every day at 23:00. To schedule the dump, open a command prompt and enter the following command:

{% code title="Command" %}

```
SchTasks /Create /SC DAILY /TN "Backup" /TR “Powershell.exe C:\Users\Administrator\backup-script.ps1" /ST 23:00
```

{% endcode %}

## Bacula and MySQL

Backups with Bacula operate at the file level and read data directly from disk. For MySQL, it isn’t always guaranteed that all data has been flushed to disk, and restoring MySQL’s raw data files doesn’t always work. Therefore, we recommend dumping the database to `.sql` files at regular intervals.

Below, we show an example of how you can schedule a database dump. Create a file with the following content and save it as `backup‑script.bat`:

{% code title="backup‑script.bat" %}

```batch
set MYSQLUSER=<Username for MySQL>
set MYSQLPASS=<Password for MySQL>
set BATCHFILE=C:\Users\Administrator\dump-database.bat
set DUMPPATH=<Path to backup directory, example C:\backup\MySQL>

echo @echo off > %BATCHFILE%
echo cd %DUMPPATH% >> %BATCHFILE%
mysql -u%MYSQLUSER% -p%MYSQLPASS% -AN -e"SELECT CONCAT('mysqldump -u%MYSQLUSER% -p%MYSQLPASS% --single-transaction -f ',schema_name,' > ',schema_name,'.sql') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','performance_schema')" >> %BATCHFILE%
type %BATCHFILE%
C:\Users\Administrator\dump-database.bat
```

{% endcode %}

### How the script works

The script connects to the MySQL database and determines which databases should be backed up. It then creates a new `.bat` file (`dump-database.bat`) where each database becomes a separate job.

The new `.bat` file is placed in `C:\Users\Administrator\` and is executed immediately after the first `.bat` file finishes.

An example of what `dump-database.bat` will look like:

{% code title="Sample dump-database.bat file" %}

```batch
@echo off  
cd C:\backup\MySQL  
mysqldump -uroot -pSuperSecretMySQLPassword --single-transaction -f datbas1 > databas1.sql
mysqldump -uroot -pSuperSecretMySQLPassword --single-transaction -f databas2 > databas2.sql
```

{% endcode %}

This script could be scheduled with the following command to save the database to a file every day at 23:00. To schedule the dump, open a command prompt and enter the following commands:

{% code title="Command" %}

```
SchTasks /Create /SC DAILY /TN "Backup" /TR “C:\Users\Administrator\backup-script.bat" /ST 23:00`
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.glesys.com/products/other/backup-bacula/how-tos/bacula-for-windows.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
