【Git】GitLab备份出现Error No Access Permission Denied

Git备份时需要mkdir,如果修改的备份路径,可能对应文件夹不属于git用户,没有权限。
即便是你root用户执行操作,实际备份时用的还是git用户,所以要将备份文件夹所有者设为git

备份脚本示例,中间有将权限交给git,然后再交回权限。

#!/bin/bash
#root user
#crontab -e
#add
#56 00 * * */home/delta/gitautobackup.sh
#every data 00:56 backup

gitBaseBackup="GitLab_Backup"
gitnewBackup=$gitBaseBackup/Backup_new
gitoldBackup=$gitBaseBackup/Backup_old

ftpUrl="192.168.10.209"
ftpUser="administrator"
ftpPasswd="Delta123"


localDir="/home/delta/GitLab_Backup"
localnewBackup=$localDir/Backup_new
localoldBackup=$localDir/Backup_old


if [ ! -d $localnewBackup ];then
mkdir -p $localnewBackup
fi

if [ ! -d $localoldBackup ];then
mkdir -p $localoldBackup
fi



if [ -f $localnewBackup/*.tar ];then
#delete old
echo "delete old backup"
rm -rf $localoldBackup/*
#move new to old
echo "move new to old"
mv $localnewBackup/*$localoldBackup
else
echo "no new backup to old"
fi




#git own backup directory
echo "change backup directory ownerto git"
chown -R git $localDir

#create new git backup
echo "GitLab Backup ..."
gitlab-rakegitlab:backup:create


#check backup is whethersuccessful
if [ ! -f $localnewBackup/*.tar ];then
cd $localDir
currentTime=`date "+%Y-%m-%d%H:%M:%S"` 
#currentTimeStamp=`date -d"$currentTime" `
echo ${currentTime}" Backup GitLaberror! exit!"
echo ${currentTime}" Backup GitLaberror! " >>GitLabBackupError.log

exit
fi

cd $localDir

#change owner back to delta
chown -R delta $localDir

#delete ftp backup
echo "push toftp" 
ftp -n<
open $ftpUrl
user $ftpUser $ftpPasswd
binary
cd $gitBaseBackup

prompt off

lcd $localnewBackup/
put *.tar
bye
!

echo "backup successful"
exit

你可能感兴趣的:(版本控制)