-
Notifications
You must be signed in to change notification settings - Fork 8
/
backup_mattermost.sh
executable file
·32 lines (26 loc) · 979 Bytes
/
backup_mattermost.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
currDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
confFile="$currDir/backup_mattermost.conf"
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
# conffile
if [ -e $confFile -a -r $confFile ]
then
source $confFile
else
echo "$confFile not found."
exit 1
fi
# prepare
rm -rf $gitlabBackupDir/mattermost
mkdir -p $gitlabBackupDir/mattermost/data
# backup data
cp -R $mattermostDir/* $gitlabBackupDir/mattermost/data
# backup postgres
su - mattermost -c "/opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production" > $gitlabBackupDir/mattermost/mattermost_production_backup.sql
# package and cleanup
backupfile=$(date +%s_%Y_%m_%d)_mattermost_backup.tar.gz
tar -zcf $gitlabBackupDir/$backupfile $gitlabBackupDir/mattermost
rm -rf $gitlabBackupDir/mattermost
# upload to S3
$awscli s3 cp $gitlabBackupDir/$backupfile $s3path
rm -f $gitlabBackupDir/$backupfile