# Bash script to automate snap backup

**URL:** <https://forums.rocket.chat/t/bash-script-to-automate-snap-backup/1907>\
**Category:** Community Support\
**Created:** [August 28, 2018, 10:00am UTC](https://forums.rocket.chat/t/bash-script-to-automate-snap-backup/1907 "2018-08-28T10:00:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![artsonica120](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@artsonica120](https://forums.rocket.chat/u/artsonica120)\
**Post date:** [August 28, 2018, 10:00am UTC](https://forums.rocket.chat/t/bash-script-to-automate-snap-backup/1907/1 "2018-08-28T10:00:50Z")

</div>

I currently manually backup my snap following [https://rocket.chat/docs/installation/manual-installation/ubuntu/snaps/#how-do-i-backup-my-snap-data](https://rocket.chat/docs/installation/manual-installation/ubuntu/snaps/#how-do-i-backup-my-snap-data)

I can run a cron nightly to create this backup, but I’d like to automate all of it with a bash script so as to be able to rsync or scp to a remote server. Essentially covering this:

1. Script stops the server then runs: **snap run rocketchat-server.backupdb**
2. Script takes the command’s output _A backup of your data can be found at_ “ **/var/snap/rocketchat-server/xxxx/backup.tgz** ” as source for the scp.
3. scp executed
4. script starts server again.

I can do 1, 3 and 4, but unsure of how to handle 2) section. Also is it really necessary to stop the server running, or is this just extra safety to avoid database corruption?

---

<div class="post-metadata">

**Author:** ![askoday](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@askoday](https://forums.rocket.chat/u/askoday)\
**Post date:** [August 29, 2018, 7:42pm UTC](https://forums.rocket.chat/t/bash-script-to-automate-snap-backup/1907/2 "2018-08-29T19:42:45Z")

</div>

Please, did the backup directory changes every time?  
If so you can use a pipe and select the backup file and it path from the message.

I don’t know commands for the selection yet.

---

<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 6, 2019, 9:55pm UTC](https://forums.rocket.chat/t/bash-script-to-automate-snap-backup/1907/3 "2019-06-06T21:55:05Z")

</div>

Here’s a topic I started with a script that could be modified to do what you want.

> [@Backup Script for Snap RocketChat](https://forums.rocket.chat/t/backup-script-for-snap-rocketchat/3827):
>
> 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: This assumes the script is being run as root This script moves everything from the initial location to a statically-named folder. This folder and the filename could easily be scripted to change. The m…
