Magento full backup

#!/bin/sh # Script can create full backup of magento site and upload it to # remote FTP server. Suitable for doing regular offsite backups. # # Depends on tar, mysqldump, gzip and curl binaries for proper work. # # Set correct FTP_HOST, FTP_USER, FTP_PASSWORD, MYSQL_HOST, MYSQL_USER, # MYSQL_PASSWORD, MYSQL_DBNAME, SITE_DOCROOT values FTP_HOST=backup.example.com FTP_USER=ftpbackup FTP_PASSWORD=SomePasswordHere MYSQL_HOST=localhost MYSQL_USER=example MYSQL_PASSWORD=SomePasswordHere MYSQL_DBNAME=example_db SITE_NAME=example.com SITE_DOCROOT=/var/www/vhosts/example.com __die() { if [ -n "$1" ]; then echo "$1" >&2 exit 1 fi } TIMESTAMP=$(date +'%Y-%m-%d_%H-%M') test -d "${SITE_DOCROOT}" || __die "Site document root not found: ${SITE_DOCROOT}" TMPPREFIX=$(mktemp -d) || __die "Unable to create temporary directory" SITE_PREFIX=$(dirname "${SITE_DOCROOT}") SITE_DIRNAME=$(basename "${SITE_DOCROOT}") tar -cf "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.tar" -C "${SITE_PREFIX}" "${SITE_DIRNAME}" || __die "Unable to create sources backup: ${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.tar" mysqldump --add-drop-table -h"${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DBNAME}" > "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.sql" || __die "Unable to create database backup: ${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.sql" nice -n 19 gzip -9 "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.tar" "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.sql" || __die "Unable to compress backup" curl --silent --upload-file "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.sql.gz" --user "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}/" || __die "Unable to upload database backup to FTP" curl --silent --upload-file "${TMPPREFIX}/${SITE_NAME}-backup-${TIMESTAMP}.tar.gz" --user "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}/" || __die "Unable to upload sources backup to FTP" test -d "${TMPPREFIX}" && rm -fr "${TMPPREFIX}"

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.