Skip to content

Commit

Permalink
Merge pull request zhblue#387 from jizhuozhi/master
Browse files Browse the repository at this point in the history
Multiplatform backup and restore
  • Loading branch information
zhblue authored Jan 21, 2019
2 parents 0c32c45 + 6915489 commit 3e1f3d8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion trunk/install/install-centos7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h l
mysqladmin -u root password $DBPASS
cd ../../

mkdir etc data log
mkdir etc data log backup

cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
Expand All @@ -45,6 +45,7 @@ sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf

chmod 700 backup
chmod 700 etc/judge.conf

#sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
Expand Down
2 changes: 1 addition & 1 deletion trunk/install/install-ubuntu14.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
mkdir etc data log
mkdir etc data log backup

cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
Expand Down
3 changes: 2 additions & 1 deletion trunk/install/install-ubuntu16+.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`

mkdir etc data log
mkdir etc data log backup

cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
Expand All @@ -27,6 +27,7 @@ sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf

chmod 700 backup
chmod 700 etc/judge.conf

sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
Expand Down
3 changes: 2 additions & 1 deletion trunk/install/install-ubuntu18.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`

mkdir etc data log
mkdir etc data log backup

cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
Expand All @@ -27,6 +27,7 @@ sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf

chmod 700 backup
chmod 700 etc/judge.conf

sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
Expand Down
39 changes: 27 additions & 12 deletions trunk/install/restore.centos7.sh → trunk/install/restore+.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ OJ_PASSWORD=`cat /home/judge/etc/judge.conf | grep OJ_PASSWORD`
DB_USERNAME=`echo ${OJ_USERNAME:13}`
DB_PASSWORD=`echo ${OJ_PASSWORD:12}`

if [ -e /home/judge/src/install/backup.centos7.sh ];then
echo "backup current archive for restoring when interrupted"
bash /home/judge/src/install/backup.centos7.sh
else
echo "no backup shell cannot create backup archive"
fi

# create temp directory
mkdir /home/judge/backup/temp

# save database config if interrupted
touch /home/judge/backup/temp/db.conf
echo DB_USERNAME=${DB_USERNAME} >> /home/judge/backup/temp/db.conf
echo DB_PASSWORD=${DB_PASSWORD} >> /home/judge/backup/temp/db.conf

# clear old files
rm -rf /home/judge/data
rm -rf /home/judge/etc
rm -rf /home/judge/src/web

# create temp directory
mkdir /home/judge/backup/temp

# start restore
tar -xf /home/judge/backup/${archive} -C /home/judge/backup/temp

Expand Down Expand Up @@ -68,9 +67,25 @@ sed -i "s/${cdbpass}/static\ \ \$DB_PASS=\"${DB_PASSWORD}\";/g" /home/judge/src/
chmod 775 -R /home/judge/data
chmod 700 /home/judge/etc/judge.conf
chmod 700 /home/judge/src/web/include/db_info.inc.php
chown -R apache:apache /home/judge/data
chown apache /home/judge/src/web/include/db_info.inc.php
chown apache /home/judge/src/web/upload

centos7=`cat /etc/os-release | grep PRETTY_NAME | grep CentOS | grep 7 `
ubuntu14=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 14`
ubuntu16=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 16`
ubuntu18=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 18`

if [ -n "${centos7}" ];then
own=apache;
elif [ -n "${ubuntu14}" ];then
own=judge;
elif [ -n "${ubuntu16}" ];then
own=www-data;
elif [ -n $"{ubuntu18}" ];then
own=www-data;
fi

chown -R ${own}:${own} /home/judge/data
chown ${own} /home/judge/src/web/include/db_info.inc.php
chown ${own} /home/judge/src/web/upload

# clear temp directory
rm -rf /home/judge/backup/temp

0 comments on commit 3e1f3d8

Please sign in to comment.