Skip to content

Instantly share code, notes, and snippets.

@jfqd
Last active September 18, 2022 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfqd/fa11f5d690124d7f4863d240a1526ca2 to your computer and use it in GitHub Desktop.
Save jfqd/fa11f5d690124d7f4863d240a1526ca2 to your computer and use it in GitHub Desktop.
Save Rocket.Chat Backup to another host and preserve the last 7 versions
#!/usr/bin/bash
# You may create a crontab entry like:
# 0 1 * * * /usr/local/bin/rc-backup
# and change the following four vars:
_URL="rc.example.com"
_USR="rc-backup"
_PWD="<long-secure-password>"
_CWD="/home/jfqd/rc-backup"
YESTERDAY=$(TZ=GMT+24 date '+%Y%m%d')
cd "%{_CWD}
curl -s -LO -u "${_USR}:${_PWD}" https://${_URL}/rc-backup/${YESTERDAY}_rocketchat.mongodump.tar.bz2
curl -s -LO -u "${_USR}:${_PWD}" https://${_URL}/rc-backup/${YESTERDAY}_rocketchat.mongodump.tar.bz2.shasum
curl -s -LO -u "${_USR}:${_PWD}" https://${_URL}/rc-backup/${YESTERDAY}_rocketchat_upload.tar.bz2
curl -s -LO -u "${_USR}:${_PWD}" https://${_URL}/rc-backup/${YESTERDAY}_rocketchat_upload.tar.bz2.shasum
ls -1dt ./*_rocketchat.mongodump.tar.bz2 | tail -n +8 | xargs rm -rf || true
ls -1dt ./*_rocketchat_upload.tar.bz2 | tail -n +8 | xargs rm -rf || true
ls -1dt ./*_rocketchat.mongodump.tar.bz2.shasum | tail -n +8 | xargs rm -rf || true
ls -1dt ./*_rocketchat_upload.tar.bz2.shasum | tail -n +8 | xargs rm -rf || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment