在ubuntu服务器上备份有数据库的网站

我有一个Ubuntu的本地服务器,我们曾经有我们所有的开发网站。 他们都是基于PHP的网站。 我想知道我们是否可以有脚本或东西cron备份文件和数据库日常外部硬盘?

请告诉我。

这是我写的一个小脚本,用于将我的apache-configs,webfiles&db备份到Amazon S3。 服务器的唯一目的是一个Web服务器,每个开发者都使用他自己的homedir。 所以,`/ home'中有一个文件需要备份的用户列表。

#!/bin/bash # 2012 Bart De Vos # This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # location of this script DIRECTORY=$(cd `dirname $0` && pwd) INSTALLER_FILENAME=`basename $0` # error handling function error_exit { echo "Error on line ${1:-'Aborting script.'}" 1>&2 exit 1 } function backup { # exit on errors set -e # getting hostname HOSTNAME_FQDN=`hostname --fqdn` || error_exit "${LINENO}: Error determening hostname" echo "Determening timestamp" timestampbackup=`/bin/date +%Y%m%d%H` || error_exit "${LINENO}: Error determening timestamp" echo "Create backupdir" /bin/mkdir /backup/${timestampbackup} || error_exit "${LINENO}: Error creating backupdir" echo "Dump and save MYSQL for all dbs" /usr/bin/mysqldump --all-databases --opt -c -e -Q -uScriptRunner -pMySuperSecretPasswordThaIAlmostForgotToRemoveFromTheScript | /bin/gzip > /backup/${timestampbackup}/sqlbackup.sql.gz || error_exit "${LINENO}: Error backing up mysql" echo "Itterate users in /home/.backup" for username in `awk -F: '{print $1}' /home/.backup` do echo "Backing up user: $username" /bin/tar -czpf /backup/${timestampbackup}/${username}.tar.gz /home/${username} || error_exit "${LINENO}: Error backing up $username" done echo "Get configs" /bin/tar -czpf /backup/${timestampbackup}/httpdconfigs.tar.gz /etc/httpd/conf.d/ || error_exit "${LINENO}: Error backing up httpd conf.d" echo "Copy to S3 bucket" /usr/bin/s3cmd --config=/backup/.s3cfg put /backup/ s3://${HOSTNAME_FQDN} --recursive || error_exit "${LINENO}: Error with transfer to S3" echo "Remove backupdir" /bin/rm /backup/${timestampbackup} -rf || error_exit "${LINENO}: Error deleting backupdir" echo "All done!" } backup 

在使用它之前,您需要安装s3cmd并使用您的S3安全证书创build一个.config文件。 (将在第一次使用时创build)。

不要忘记检查/改变path,因为它们可以在发行版/版本之间有所不同。