better backup
This commit is contained in:
parent
7aeadb73f6
commit
84ae2f07e2
@ -1,15 +1,114 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
DIR=$1
|
DIR_PATH=${1}
|
||||||
|
DIR=$(/usr/bin/basename ${DIR_PATH})
|
||||||
|
LOG="${DIR}.log"
|
||||||
|
TIMESTAMP=$(/usr/bin/date +%Y/%m/%d' '%H:%M:%S)
|
||||||
|
|
||||||
[ $# -lt 1 ] && echo "Directory argument is missing" && exit
|
#
|
||||||
[ $# -gt 1 ] && echo "Too many arguments" && exit
|
# show to screen also and write to file
|
||||||
[ ! -d $DIR ] && echo "Directory ${DIR} does not exist" && exit
|
#
|
||||||
|
function log() {
|
||||||
|
echo -e "\e[96m`date +'%d/%m/%Y %H:%M:%S'`\e[39m ${1}"
|
||||||
|
echo -e "`date +'%d/%m/%Y %H:%M:%S'` ${1}" >> $LOG
|
||||||
|
}
|
||||||
|
|
||||||
echo -ne " 🔎 Verify file"
|
#
|
||||||
bzip2 -tv $TAR
|
# database - get credentials
|
||||||
[ $? -ne 0 ] && "Cannot verify $TAR" && exit
|
#
|
||||||
|
function get_db_credentials() {
|
||||||
|
SETTINGS=$(find ${DIR} -name settings.php | grep default)
|
||||||
|
DATABASE=$(cat $SETTINGS | tr -d ' ' | grep "^'database'" | awk -F\' '{print $4}')
|
||||||
|
USERNAME=$(cat $SETTINGS | tr -d ' ' | grep "^'username'" | awk -F\' '{print $4}')
|
||||||
|
PASSWORD=$(cat $SETTINGS | tr -d ' ' | grep "^'password'" | awk -F\' '{print $4}')
|
||||||
|
|
||||||
./db -e ${DIR}
|
[[ -z "${SETTINGS}" ]] && log "Empty variable SETTINGS" && return 1
|
||||||
tar -cjpf ${DIR}.tar.bz2 ${DIR} ${DIR}.*
|
[[ -z "${DATABASE}" ]] && log "Empty variable DATABASE" && return 1
|
||||||
ls -l ${DIR}.tar.bz2 --color=auto
|
[[ -z "${USERNAME}" ]] && log "Empty variable USERNAME" && return 1
|
||||||
|
[[ -z "${PASSWORD}" ]] && log "Empty variable PASSWORD" && return 1
|
||||||
|
|
||||||
|
log "SETTINGS: ${SETTINGS}"
|
||||||
|
log "DATABASE: ${DATABASE}"
|
||||||
|
log "USERNAME: ${USERNAME}"
|
||||||
|
log "PASSWORD: ${PASSWORD}"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# database - verify credentials
|
||||||
|
#
|
||||||
|
function verify_db_credentials() {
|
||||||
|
mysql -u"${USERNAME}" -p"${PASSWORD}" --batch --skip-column-names -e "SHOW DATABASES;" | grep "${DATABASE}" > /dev/null;
|
||||||
|
|
||||||
|
if [ $? -ne 0 ];then
|
||||||
|
log "Verify database credentials [FAIL]"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Verify database credentials [ OK ]"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# database - export data
|
||||||
|
#
|
||||||
|
function export_db() {
|
||||||
|
mysqldump -u"${USERNAME}" -p"${PASSWORD}" ${DATABASE} > ${DATABASE}.sql
|
||||||
|
|
||||||
|
if [ $? -ne 0 ];then
|
||||||
|
log "Export database [FAIL]"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Export database [ OK ]"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check the path
|
||||||
|
#
|
||||||
|
function check_path() {
|
||||||
|
[ ! -d ${DIR} ] && log "${TIMESTAMP} ${DIR} does not exist" && return 1
|
||||||
|
[ ! -f ${DIR}/web/sites/default/settings.php ] && \
|
||||||
|
[ ! -f ${DIR}/sites/default/settings.php ] && log "${TIMESTAMP} Cannot find setting.php" && return 1
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create tarball
|
||||||
|
#
|
||||||
|
function create_tarball() {
|
||||||
|
log "Create backup-${DIR}.tar.gz"
|
||||||
|
tar -czpf "backup-${DIR}.tar.gz" "${DIR}" "${DIR}.sql"
|
||||||
|
[ $? -ne 0 ] && return 1
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_checksum() {
|
||||||
|
log "Create backup-${DIR}-md5sum checksum"
|
||||||
|
CHECKSUM=$(md5sum backup-${DIR}.tar.gz | awk '{print $1}' )
|
||||||
|
echo ${CHECKSUM} > "backup-${DIR}.md5sum"
|
||||||
|
}
|
||||||
|
|
||||||
|
function main () {
|
||||||
|
if check_path; then
|
||||||
|
if get_db_credentials; then
|
||||||
|
if verify_db_credentials; then
|
||||||
|
if export_db; then
|
||||||
|
if create_tarball; then
|
||||||
|
create_checksum
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ ${#} -lt 1 ] && log "${TIMESTAMP} Directory argument is missing" && return 1
|
||||||
|
[ ${#} -gt 1 ] && log "${TIMESTAMP} Too many arguments" && return 1
|
||||||
|
|
||||||
|
main
|
||||||
|
|
||||||
|
ls -lh backup-${DIR}.tar.gz --color=auto
|
||||||
|
ls -lh backup-${DIR}.md5sum --color=auto
|
||||||
|
|||||||
@ -10,7 +10,6 @@ BB="\e[1;34m"
|
|||||||
BW="\e[1;97m"
|
BW="\e[1;97m"
|
||||||
E="\e[00m"
|
E="\e[00m"
|
||||||
|
|
||||||
|
|
||||||
DBUSER="root"
|
DBUSER="root"
|
||||||
DBPASS="1234"
|
DBPASS="1234"
|
||||||
|
|
||||||
@ -30,8 +29,7 @@ echo
|
|||||||
read -p "Note for destination $DST.log: " NOTE
|
read -p "Note for destination $DST.log: " NOTE
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
echo -ne " 📦 Copy files from $SRC to $DST"
|
||||||
echo -ne " 🍄 Copy files from $SRC to $DST"
|
|
||||||
cp -rp $SRC $DST
|
cp -rp $SRC $DST
|
||||||
[ -f "$SRC.copy.log" ] && cp $SRC.copy.log $DST.copy.log
|
[ -f "$SRC.copy.log" ] && cp $SRC.copy.log $DST.copy.log
|
||||||
echo >> $DST.copy.log
|
echo >> $DST.copy.log
|
||||||
@ -70,11 +68,6 @@ fi
|
|||||||
sed -i "s/$SRC/$DST/g" $CONFIG
|
sed -i "s/$SRC/$DST/g" $CONFIG
|
||||||
log $?
|
log $?
|
||||||
|
|
||||||
# echo -ne " 🍒 link html to $DST"
|
|
||||||
# unlink /var/www/html
|
|
||||||
# ln -s /var/www/sites/$DST /var/www/html
|
|
||||||
# if [ $? = 0 ]; then ok; else fail; fi
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
ls -l --color=auto /var/www/site[0123456789]
|
ls -l --color=auto /var/www/site[0123456789]
|
||||||
echo
|
echo
|
||||||
|
|||||||
@ -36,12 +36,11 @@ NAME=$(echo $1 | tr -d '^\./')
|
|||||||
# cd ../..
|
# cd ../..
|
||||||
# fi
|
# fi
|
||||||
echo "<html><head></head><body><pre style='font: monospace'>"
|
echo "<html><head></head><body><pre style='font: monospace'>"
|
||||||
|
|
||||||
COUNT=$(vendor/drush/drush/drush route | grep "/api/" | wc -l)
|
COUNT=$(vendor/drush/drush/drush route | grep "/api/" | wc -l)
|
||||||
echo
|
echo
|
||||||
echo -e "🌐 GET endpoints: ${COUNT}"
|
echo -e "🌐 GET endpoints: ${COUNT}"
|
||||||
echo
|
echo
|
||||||
vendor/drush/drush/drush route | grep "/api/" | awk {'print $2'} | sed "s/'//g"
|
vendor/drush/drush/drush route | grep "/api/" | awk {'print $2'} | sed "s/'//g" | sort
|
||||||
|
|
||||||
# if [[ -f ./web/modules/custom ]]; then
|
# if [[ -f ./web/modules/custom ]]; then
|
||||||
# cd ./web/modules/custom
|
# cd ./web/modules/custom
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user