> 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-linux.md).

# Bacula for Linux

***

Log in to your server via SSH. To install the packages required for Bacula to work, you need to log in as root.

Run this command to install the Bacula software (note that the exact command may vary depending on which Linux distribution you are using):

{% code title="Command" %}

```
apt-get install bacula-client
```

{% endcode %}

Open the file `/etc/bacula/bacula-fd.conf` and replace the existing content with the configuration shown below.

If your server is placed in Stockholm:

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

```
Director {
        Name = bacula02-fbg-fd
        Password = "YourPasswordGoesHere"
}  
FileDaemon {
        Name = ds*****
        FDport = 9102
        FDAddress = 0.0.0.0
        WorkingDirectory = /var/lib/bacula
        Pid Directory = /var/run/bacula
        Maximum Concurrent Jobs = 20
}  
Director {
        Name = bacula02-fbg-mon
        Password = "LkRjyq760wGbAXeah4ofS55bG41q4p"
        Monitor = yes
}  
Messages {
        Name = "Standard"
        director = bacula02-fbg-dir = all, !skipped
}
```

{% endcode %}

If your server is placed in Falkenberg:

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

```
Director {
        Name = bacula06-vbdc-dir
        Password = "YourPasswordGoesHere"
}
FileDaemon {
        Name = ds*****
        FDport = 9102
        FDAddress = 0.0.0.0
        WorkingDirectory = /var/lib/bacula
        Pid Directory = /var/run/bacula
        Maximum Concurrent Jobs = 20
}
Director {
        Name = bacula06-vbdc-mon
        Password = "gRTYk9qEJebexvA4BtguTCQ26kmo4J9ajY"
        Monitor = yes
}
Messages {
        Name = Standard
        director = bacula06-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`.

Bacula requires the directories `/var/lib/bacula` and `/var/run/bacula` to exist (unless you have specified different paths in your configuration).

If they were not created during installation, create them with:

{% code title="Command" %}

```
mkdir -p /var/lib/bacula /var/run/bacula
```

{% endcode %}

Then, restart Bacula by using the command:

{% code title="Command" %}

```
/etc/init.d/bacula-client restart
```

{% endcode %}

Enter your password in the form at <https://secrets.glesys.com/> and send the link together with a list of the directories you want to back up to <support@glesys.se>. Preferably in the format shown below:

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

```
- name: 'ds****'
  address: '1.2.3.4'
  password: 'YourPasswordGoesHere'
  files: ['/root', '/etc', '/usr/local', '/var/spool/cron', '/home']
  excludes: ['/home/mapp1', '/home/mapp2']
  runbeforejob: '/usr/local/bin/mysqlbackup.sh root NOPASS /root/mysqldumps'
  storage: 150
  email: kund@mail.toppdomän
```

{% endcode %}

Keep in mind that if you are using a firewall to protect your server, you need to allow traffic from Bacula; the `iptables` rules are listed below:

{% code title="iptables rules to allow traffic from Bacula" %}

```
iptables -A INPUT -p TCP --dport 9102 -s 195.20.207.32/28 -j ACCEPT # Bacula_VBDC
iptables -A INPUT -p TCP --dport 9102 -s 195.238.77.0/28 -j ACCEPT # Bacula_FBG
iptables -A OUTPUT -p TCP --dport 9103 -d 195.20.207.32/28 -j ACCEPT # Bacula_VBDC
iptables -A OUTPUT -p TCP --dport 9103 -d 195.238.77.0/28 -j ACCEPT # Bacula_FBG
iptables -A INPUT -p TCP --sport 9103 -m state --state ESTABLISHED -j ACCEPT # Bacula
```

{% endcode %}

## MySQL backup with Bacula

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.

Example script for dumping data in MySQL:

{% code title="/root/mysqlbackup.sh" %}

```bash
#!/bin/sh
if [ -z $3 ]; then
    echo "Wrong syntax..."
    echo "use: $0 <mysql_root> <mysql_password> <dump_dir>"
    exit
fi
echo Dumping MySQL database to $3.
umask 077
rm $3/*
mkdir $3 &>/dev/null
cd $3
for i in `echo "SHOW DATABASES" |/usr/bin/mysql -s -u $1 -p$2`; do
     /usr/bin/mysqldump --single-transaction -f -u $1 -p$2 $i >$i.sql
    if [ $? -ne 0 ] ; then
            echo ERROR: Fail when dumping $i
    fi
done
du -sh $3
echo Databasedump done
```

{% endcode %}

This script could be scheduled in crontab with the following entry to save the database to a file every day at 22:00.

{% code title="Example crontab entry" %}

```
0 22 * * * /root/mysqlbackup.sh root YOUR_DATABASE_PASSWORD /root/mysqldumps
```

{% endcode %}
