initial commit

This commit is contained in:
2023-05-10 21:23:04 -04:00
commit b5e8dc72cb
2 changed files with 63 additions and 0 deletions

56
wp-backup.sh Normal file
View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Wordpress backup script.
# Uses zip compression since most clients won't know how
# to decompress other formats like .tgz or .7z.
# Example cron entry:
# 0 6 * * 1 /root/wp-backup.sh /var/www/wordpress /tmp/ >/root/wp-backup.log 2>&1
TODAY=$(date +%Y%m%d)
WP_PATH=${1}
ARCHIVE_DIR=${2}/backup-${TODAY}
NCUSER=__CHANGEME__
NCURL="https://__CHANGEME__/remote.php/dav/files/$NCUSER/HostingBackups"
NCPASS='__CHANGEME__'
if [ $# -lt 2 ]; then
echo "$0 <wp_path> <archive_dir"
exit 1
fi
if [ ! -f /usr/bin/wp ]; then
echo downloading wp-cli...
curl -s -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo mv wp-cli.phar /usr/bin/wp; sudo chmod +x /usr/bin/wp
sudo apt-get install -y zip 2>/dev/null
fi
if [ ! -f /usr/bin/zip ]; then
echo downloading zip...
sudo apt-get install -y zip 2>/dev/null
fi
upload() {
client_dir=$(hostname)
printf "[*] CREATING DIRECTORY ${client_dir}..."
if curl -u $NCUSER:$NCPASS -X MKCOL "$NCURL/${client_dir}">/dev/null 2>&1; then
printf "OK\n"
else
printf "FAILED\n"
fi
printf "[*] UPLOADING ${1}..."
if curl -u $NCUSER:$NCPASS -T ${1} "$NCURL/${client_dir}/${1}"; then
printf "OK\n"
rm -f ${1}
else
printf "FAILED\n"
fi
}
mkdir -p ${ARCHIVE_DIR}
cp -r ${WP_PATH} ${ARCHIVE_DIR}/
sudo -u www-data wp db export --path=${1} ${ARCHIVE_DIR}/website.sql >/dev/null 2>&1
cd $(dirname ${ARCHIVE_DIR})
zip -r backup-${TODAY}.zip $(basename ${ARCHIVE_DIR})
rm -rf ${ARCHIVE_DIR}
upload backup-${TODAY}.zip