Backup Script for Snap RocketChat

Hey Peeps,

I couldn’t easily find a script to automate the snap rocketchat backups so I wrote a quick and dirty one. I thought I’d drop it here in case it helps somebody else out. Please feel free to edit and add your improvements. That’s what the community is for. Go Team!

A couple of things:

  1. This assumes the script is being run as root
  2. This script moves everything from the initial location to a statically-named folder. This folder and the filename could easily be scripted to change.
  3. The move command will only occur on a successful completion of the backup command

Script:

#!/bin/bash
#Variables 
backup_destination="/path/to/backup/destination"
backup_location="/path/to/backup/location"

#Start of command section
service snap.rocketchat-server.rocketchat-server stop
    
snap run rocketchat-server.backupdb &&

mv $backup_location/* $backup_destination

service snap.rocketchat-server.rocketchat-server start

#Clean up everything in destination folder older than 7 days
find $backup_destination/* -mtime +7 -exec rm {} \;
2 Likes

I don’t think it is worth using snap command. This one is directly from database directly to where you please:

#!/bin/bash
BackupDestination=/mnt/bkpspace/`hostname`.`dnsdomainname`/RocketChat
if [ ! -d $BackupDestination ] ; then
  mkdir -p $BackupDestination
fi

/snap/rocketchat-server/current/bin/mongodump --archive=$BackupDestination/RC$(date +%Y-%m-%d-%H%M%S).gz --gzip &> $BackupDestination/RC$(date +%Y-%m-%d-%H%M%S).log

#Clean up backups older than a week
find $BackupDestination/* -mtime +7 -exec rm {} \;

Thanks! Can this be run while RC is running? You’ll notice that I have to stop the service to perform the backup currently.

Well, it is only the database backup. You don’t need to stop anything. The database has to guarantee the data integrity.

could u give me a backup restore procedure for docker rocket chat? @OlegBarkov

could u give me a backup restore procedure for docker rocket chat

Your query is about docker, not snap.

You can find plenty of information around about backing up mongo from docker - just have a web search eg