sh 在更新每个cod之前,备份文件目录,db.ini文件和(优化的)数据库SQL文件,以获取完整的Omeka安装目录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在更新每个cod之前,备份文件目录,db.ini文件和(优化的)数据库SQL文件,以获取完整的Omeka安装目录相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# UPDATE OMEKA SITE

#DON'T FORGET THE LEADING AND TRAILING SLASHES ON THE DIRECTORY PATHS!!!

# directory containing one or more Omeka installations, each in their own directory
APPSDIR=~/apps/

# directory containing latest version of Omeka (including any custom plugins and themes)
MASTERDIR=~/master/

#directory where a timestamped backup copy should be stored
BACKUPS=~/upgrade-backups/

# name of this script file
ME="${0##*/}"

# the formatted time stamp used for backups
NOW=$(date +"%Y-%m-%d_%R")

# colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NOCOLOR='\033[0m'

test -d $APPSDIR || { echo -e "${RED}Apps directory not found at $APPSDIR${NOCOLOR}"; exit 1; }
test -d $MASTERDIR || { echo -e "${RED}Master directory not found at $MASTERDIR${NOCOLOR}"; exit 2; }
test -d $BACKUPS || mkdir -p $BACKUPS || { echo -e "${RED}Unable to create Backups directory at $BACKUPS${NOCOLOR}"; exit 3; }

echo "** ======================================================== **"
echo "** Initiating $ME"
echo "** The existing production sites are set to $APPSDIR"
echo "** The latest master codebase is set to $MASTERDIR"
echo "** The backup directory is set to $BACKUPS"
echo "** ======================================================== **"

SUMMARY=""

for Dir in $(find $APPSDIR* -maxdepth 0 -type d );
do
	if grep -q OMEKA_VERSION $Dir/bootstrap.php
	then
		echo "........ backing up $(basename $Dir)";
		
			# Stuff to backup...
			FILES=$Dir/files
			DBINI=$Dir/db.ini
			
			# zip up the 'files' directory
			if [ -d $FILES ]
			then
				zip -rv $BACKUPS$(basename $Dir)_$NOW $Dir/files
			else
				MSG="$(basename $Dir): No files directory found at $FILES"
				echo $MSG
				SUMMARY+="\n$MSG"
			fi
		
			# zip up the db.ini file
			if [ -f $DBINI ]
			then
				zip -v $BACKUPS$(basename $Dir)_$NOW $Dir/db.ini
			else
				MSG="$(basename $Dir): No db.ini file found at $DBINI"
				echo $MSG
				SUMMARY+="\n$MSG"
			fi

			# read db.ini info
			DBUSER=`grep "^username" $DBINI | awk -F\" '{print $(NF-1)}'`
			DBPASS=`grep "^password" $DBINI | awk -F\" '{print $(NF-1)}'`
			DBNAME=`grep "^dbname" $DBINI | awk -F\" '{print $(NF-1)}'`	
			
			# backup the database
			if [[ ${#DBNAME} > 0 ]] && [[ ${#DBPASS} > 0 ]] && [[ ${#DBUSER} > 0 ]]
			then
					
				# optimize
				MYSQL_PWD=$DBPASS mysqlcheck -o -u $DBUSER $DBNAME
				
				#copy to backups
				SQLDUMP=$Dir/$DBNAME.sql
				MYSQL_PWD=$DBPASS mysqldump -u $DBUSER $DBNAME > $SQLDUMP
				zip -v $BACKUPS$(basename $Dir)_$NOW $SQLDUMP
				rm $SQLDUMP	
							
			else
				MSG="$(basename $Dir): Unable to backup database!"
				echo $MSG
				SUMMARY+="\n$MSG"			
			fi
		
		echo "........ updating $(basename $Dir)";
			if [ -d $FILES ] && [ -f $DBINI ]
			then
				# update core
				rsync -av --exclude='files' --exclude='plugins' --exclude='themes' --exclude='db.ini' --exclude=".*" --exclude=".*/" $MASTERDIR $Dir
				
				#update plugins and themes (omitted above to account for some sites having additional plugins and themes installed)
				rsync -av $MASTERDIR"plugins/" $Dir/plugins/
				rsync -av $MASTERDIR"themes/" $Dir/themes/
			else
				MSG="$(basename $Dir): Not updated! Something went wrong with the backup. Please review messages."
				echo $MSG
				SUMMARY+="\n$MSG"			
			fi	
	else
		MSG="$(basename $Dir): Not an Omeka site."
		echo $MSG
		SUMMARY+="\n$MSG"			
	fi	
done

if [[ ${#SUMMARY} > 0 ]]
	then 
		echo -e "${YELLOW}DONE. SEE MESSAGES! (Don't forget to login to each site and click through the database and plugin upgrades!) ${RED}$SUMMARY${NOCOLOR}"
	else
		echo -e "${GREEN}DONE. NO MESSAGES (Don't forget to login to each site and click through the database and plugin upgrades!)${NOCOLOR}"	
fi

以上是关于sh 在更新每个cod之前,备份文件目录,db.ini文件和(优化的)数据库SQL文件,以获取完整的Omeka安装目录的主要内容,如果未能解决你的问题,请参考以下文章

sh Unix Linux Bash RSync备份从文件目录到备份目录

sh Unix Linux Bash RSync备份从文件目录到备份目录

sh 将文件系统备份到当前目录为压缩tarball

sh 将当前目录中的单个文件备份为FileName~

shell备份,重命名,删除目录下面的文件

Linux下定时备份文件