-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcronbkp
More file actions
executable file
·44 lines (35 loc) · 1.13 KB
/
cronbkp
File metadata and controls
executable file
·44 lines (35 loc) · 1.13 KB
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
#!/usr/bin/env bash
# Project Information.
project_root=""
project_dir=""
db_dir=""
files_dir=""
# Database Information.
db_user=""
db_pass=""
db_host=""
db_name=""
# Clear Cache
cd ${project_root}/${project_dir}
drush cr
# Build backup paths and file names.
backup_path="/usr/local/lib/${project_dir}"
if [ ! -d "${backup_path}/${db_dir}" ]; then
mkdir -p "${backup_path}/${db_dir}"
fi
db_bkps_path="${backup_path}/${db_dir}"
if [ ! -d "${backup_path}/${files_dir}" ]; then
mkdir -p "${backup_path}/${files_dir}"
fi
files_bkps_path="${backup_path}/${files_dir}"
date="$(date +"%Y%m%d")"
filename="${project_dir}_${date}"
# Dump database to SQL file.
sqldump_path="$(which mysqldump)"
${sqldump_path} -u ${db_user} --password=${db_pass} --host=${db_host} ${db_name} > "${db_bkps_path}/${filename}_db.sql"
# Compress backups.
gzip "${db_bkps_path}/${filename}_db.sql"
tar -zcf "${files_bkps_path}/${filename}_files.tar.gz" -C ${project_root}/${project_dir}/web/sites/default/ files
# Delete backups older than 30 days
find ${db_bkps_path}/* -name *.gz -mtime +30 -exec rm {} \;
find ${files_bkps_path}/* -name *.gz -mtime +30 -exec rm {} \;