-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghost.backup
110 lines (93 loc) · 2.77 KB
/
ghost.backup
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /bin/bash
# -----
# Ghost.org blogging platform backup script
# This script is a part of SCI Ghost Toolkit
#
# Usage: ghost.backup /path/to/ghost /way/to/backup
# ghost.backup /path/to/ghost
#
# Note: By default, script backups ghost to /var/backups/ghost
# -----
# Author: Adanos Flamel, SCI
# adanos@stormcage.ru
# -----
# ----- Checking run mode ----- Begin -----
if [[ $(echo $* | grep -e "--chain") ]]; then
backupmode=0
else
backupmode=1
fi
# ----- Checking run mode ----- End -----
# ----- Checks for standalone mode ----- Begin -----
if [[ backupmode -eq 1 ]]; then
# Some configuration things
PATH=$PATH:.
# ----- Print usage message----- Begin -----
if [[ $(echo $* | grep -e "--help") ]]; then
. ghost.assets backup_help
exit $?
fi
# ----- Print usage message ----- End -----
# ----- Require arguments ----- Begin -----
if [[ $* == "" || $# < 1 ]]; then
echo -e "[Ghost Backup]: Missing arguments.\n" \
"Usage: ghost.backup /path/to/ghost \n" \
" ghost.backup /path/to/ghost /way/to/backup \n"
exit 2
fi
# ----- Require arguments ----- End -----
# ----- Require root access ----- Begin -----
if [[ $UID != 0 ]]; then
echo "[Ghost Backup]: Please run this script with sudo:"
echo "sudo $0 $*"
exit 3
fi
# ----- Require root access ----- End -----
# ----- Setup paths ----- Begin -----
ghostpath=$1 # Path to ghost installation
if [[ -z $2 ]]; then
ghostbackuppath="/var/backups/ghost"
else
ghostbackuppath=$2
fi
if [[ -z $ghostworkpath ]]; then
ghostworkpath="/tmp/ghosttemp"
mkdir -p $ghostworkpath
fi
# ----- Setup paths ----- End -----
fi
# ----- Checks for standalone mode ----- End -----
# ----- The script itself ----- Begin -----
ghostbackupdate=`date +"%Y%m%d"`
# Checking backup path is specified
if [[ ! -z $(echo $* | grep -e "--chain") && -z $2 ]]; then
ghostbackuppath="/var/backups/ghost"
fi
echo "[Ghost Backup]: Copying files to $ghostworkpath"
rsync -Aax $ghostpath/content $ghostworkpath/
if [[ $? -ne 0 ]]; then
echo "[Ghost Backup]: Failed copying content."
exit 6
fi
rsync -Aax $ghostpath/config.js $ghostworkpath/
if [[ $? -ne 0 ]]; then
echo "[Ghost Backup]: Failed copying config."
exit 7
fi
echo "[Ghost Backup]: Archiving files to $ghostbackuppath"
if [[ ! -d $ghostbackuppath ]]; then
mkdir -p $ghostbackuppath
fi
tar -caf $ghostbackuppath/ghost-`basename $ghostpath`-backup-$ghostbackupdate.tar.bz2 $ghostworkpath
if [[ $? -ne 0 ]]; then
echo "[Ghost Backup]: Archiving failed."
exit 8
else
echo "[Ghost Backup]: Backup successfull."
fi
# ----- The script itself ----- End -----
# Clear working folder case standalone
if [[ backupmode -eq 1 ]]; then
echo "[Ghost Backup]: Removing working directory."
rm -rf $ghostworkpath
fi