# Backup Script for Snap RocketChat

**URL:** <https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827>\
**Category:** Community Creations\
**Created:** [May 16, 2019, 3:37pm UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827 "2019-05-16T15:37:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![88fingerslukee](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/88fingerslukee/32/1031_2.png) [@88fingerslukee](https://forums.rocket.chat/u/88fingerslukee)\
**Post date:** [May 16, 2019, 3:37pm UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/1 "2019-05-16T15:37:46Z")

</div>

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 {} \;
```

---

<div class="post-metadata">

**Author:** ![OlegBarkov](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/olegbarkov/32/1827_2.png) [@OlegBarkov](https://forums.rocket.chat/u/OlegBarkov)\
**Post date:** [June 8, 2020, 12:06pm UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/2 "2020-06-08T12:06:45Z")

</div>

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 {} \;
```

---

<div class="post-metadata">

**Author:** ![88fingerslukee](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/88fingerslukee/32/1031_2.png) [@88fingerslukee](https://forums.rocket.chat/u/88fingerslukee)\
**Post date:** [June 8, 2020, 4:24pm UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/3 "2020-06-08T16:24:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OlegBarkov](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/olegbarkov/32/1827_2.png) [@OlegBarkov](https://forums.rocket.chat/u/OlegBarkov)\
**Post date:** [June 30, 2020, 7:01am UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/4 "2020-06-30T07:01:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hafija](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@hafija](https://forums.rocket.chat/u/hafija)\
**Post date:** [April 29, 2021, 8:01am UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/5 "2021-04-29T08:01:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [May 3, 2021, 11:18am UTC](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827/6 "2021-05-03T11:18:25Z")

</div>

> 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

> <https://stackoverflow.com/questions/60235166/best-strategy-to-backup-mongodb-docker-instance>
