Created
July 19, 2018 01:30
-
-
Save LostinOrchid/6833d773a43698612ebc978683472df3 to your computer and use it in GitHub Desktop.
Make backup for a wordpress site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
project_root=$1 | |
tmp_dir=$project_root/.tmp | |
files_dir=$tmp_dir/files | |
include_db=1 | |
files=( | |
wp-config.php | |
wp-content/themes/zeko | |
wp-content/themes/zeko-child | |
wp-content/plugins/bekipride-tools | |
) | |
echo "Current working directory $(pwd)" | |
echo "\$0 $0" | |
# helpers | |
bold="" | |
underline="" | |
standout="" | |
normal="" | |
black="" | |
red="" | |
green="" | |
yellow="" | |
blue="" | |
magenta="" | |
cyan="" | |
white="" | |
# check if stdout is a terminal... | |
if test -t 1; then | |
# see if it supports colors... | |
ncolors=$(tput colors) | |
if test -n "$ncolors" && test $ncolors -ge 8; then | |
bold="$(tput bold)" | |
underline="$(tput smul)" | |
standout="$(tput smso)" | |
normal="$(tput sgr0)" | |
black="$(tput setaf 0)" | |
red="$(tput setaf 1)" | |
green="$(tput setaf 2)" | |
yellow="$(tput setaf 3)" | |
blue="$(tput setaf 4)" | |
magenta="$(tput setaf 5)" | |
cyan="$(tput setaf 6)" | |
white="$(tput setaf 7)" | |
fi | |
fi | |
function log_and_run | |
{ | |
echo "Running command: ${green}$1${normal}" | |
$1 | |
} | |
function copy_b | |
{ | |
the_copy=$project_root/$1 | |
dir_of_copy=$(dirname $1) | |
if [ "$dir_of_copy" == "." ]; then | |
dir_of_copy="" | |
fi | |
full_clone_dir=${files_dir}/${dir_of_copy} | |
if [ ! -z "$dir_of_copy" ]; then | |
log_and_run "mkdir -p "$full_clone_dir"" | |
fi | |
log_and_run "cp -r "$the_copy" "$full_clone_dir"" | |
} | |
function make_export_file | |
{ | |
log_and_run "wp db export "$files_dir/db-$(date "+%y%m%d%H%M%S%z").sql" --path="$project_root"" | |
} | |
function run | |
{ | |
log_and_run "rm -rf $files_dir" | |
log_and_run "mkdir -p $files_dir" | |
for item in ${files[*]} | |
do | |
copy_b "${item}" | |
done | |
if [ $include_db -eq 1 ]; then | |
make_export_file | |
fi | |
log_and_run "cd $files_dir" | |
folder_name=${PWD##*/} | |
log_and_run "cd ../" | |
log_and_run "tar -zcf the_file.tar.gz $folder_name" | |
} | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment