Skip to main content

Manual Backups

in Via the CLI
Authors list
Published: Feb 8, 2022|Last updated: Apr 23, 2024

Your data within your Deskpro helpdesk is stored either in the database, or as an attachment. We recommend ensuring that both of these are backed up on a regular basis and stored off-server.

Warning


The commands below will create backups which will be stored on your helpdesk until you remove them.

Please ensure that you have enough free space available before running these commands.

You can see how much space you have available with the df -h command.

We also recommend moving these files off the server as soon as possible to prevent any storage issues.

Backing up your database - mysqldumpCopy link to Backing up your database - mysqldump to clipboard

Deskpro uses MySQL as a database engine, which has the function mysqldump to export databases. This can be used to do a one-time backup of the database, which can be useful for migrations or before making database changes.

The following command should work for most helpdesks:

sudo mysqldump --opt -Q --hex-blob {instance_id} > ~/{instance_id}.sql
copy

You will need to replace {instance_id} with the ID of your instance and the file will be created in your home (~/) directory.

TroubleshootingCopy link to Troubleshooting to clipboard

Access Denied

If you see the following error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
copy

You need to enter your database credentials in order to run this command. If you know your database root password (this may differ from your server root password), you can add the flag -p to the command to be prompted for the password:

sudo mysqldump --opt -Q -p --hex-blob {instance_id} > ~/{instance_id}.sql
copy

If you do not know your database root password, you can fall back to using the credentials Deskpro uses to access your database. These can be found in /opt/deskpro/data/instances/{instance_id}/services/deskpro/config/deskpro-config.php.

You can then use these credentials by specifying the user with -u{user} and prompting for the password with -p:

sudo mysqldump --opt -Q -u{user} -p --hex-blob {instance_id} > ~/{instance_id}.sql
copy

External MySQL servers

If you are using an external MySQL server, you can still perform the mysqldump, but you need to also specify the IP or hostname of the external server with the -h flag. You will also have to specify a user which is allowed to access the database from the server you're on.

We recommend using the credentials Deskpro are using (as the above example) if this applies to your instance.

sudo mysqldump --opt -Q -u{user} -p -h {IP or hostname} --hex-blob {instance_id} > ~/{instance_id}.sql
copy

Backing up your attachmentsCopy link to Backing up your attachments to clipboard

FilesystemCopy link to Filesystem to clipboard

If you are using the filesystem to store your attachments, these will be stored by default in /opt/deskpro/data/instances/{instance_id}/attachments

You can compress these into a tarball with the following command:

sudo tar cvzf ~/{instance_id}.tar.gz /opt/deskpro/data/instances/{instance_id}/attachments
copy

This will create a tarball in your home directory (~/) containing your attachments.

S3Copy link to S3 to clipboard

We recommend following your S3 provider's best practices for backing up attachments stored in S3.

Restoring your backupCopy link to Restoring your backup to clipboard

You should now have either 2 backup files (a .sql file and a .tar.gz file), or a database backup (.sql) and a restored S3 bucket.

Recreating your instanceCopy link to Recreating your instance to clipboard

To restore your backup, you will first need to ensure you have a working OPC. If not, you will need to follow the installation instructions for a fresh install:

Once you have a working OPC, you will need to create a new instance. With this new instance, you may have a new Instance ID which will need to be placed in {new_instance_id} in the following commands.

Restoring your databaseCopy link to Restoring your database to clipboard

With your recreated instance, you will need to restore your database. To do so, you will need to empty your new instance's database and recreate it in MySQL:

mysql
copy
Note


Logging into MySQL uses the same flags as the mysqldump command earlier to authenticate. If you do not have your username and password, you can find it in the same location with this new instance, and login by adding -u{user} -p to the end of the command. If your database server is external, you will also need to add the host with the -h {host} flag.

After logging into your MySQL prompt, first drop your database and then recreate it with the following commands:

DROP DATABASE {new_instance_id}; CREATE DATABASE {new_instance_id};
copy

Exit the MySQL prompt.

exit
copy

Now you're back on your bash prompt, you can now import the sql file into the new database:

mysql {new_instance_id} < ~/{instance_id}.sql
copy

The MySQL backup will now restore into the new instance's database.

Restoring your attachments - FilesystemCopy link to Restoring your attachments - Filesystem to clipboard

With the new instance created, you will need to extract your tarball backup into the new attachments directory of the restored instance. Assuming the backup file is stored in your home directory (~/), the command to do so is as follows:

sudo tar xzvfC ~/{instance_id}.tar.gz /opt/deskpro/data/instances/{new_instance_id}
copy
Note


The backup retains the file structure and will extract into an attachments directory, so you need to extract your files one level above.

You will now need to confirm the ownership of the files is correct by running the following command:

chown -R deskpro:deskpro /opt/deskpro/data/instances/{new_instance_id}/attachments
copy

Restoring your attachments - S3Copy link to Restoring your attachments - S3 to clipboard

As the S3 bucket will retain the attachments and file structure, you will simply need to re-attach the S3 bucket to your instance to restore access to your files.

To do that, please follow the guide on configuring an S3 bucket.

HelpfulUnhelpful
next pageConsiderations for External Backups
previous pageBacking up your instance

Please log in or register to submit a comment.