Why
- 使用
gitlab
作为文件服务器的管理中心 - 使用
gitlab ci
自动下载文件,并存储到文件服务器上 - 使用
rsync
同步两台文件服务器内容
知识点
shell遍历文件目录
#!/bin/bash
read_dir(){
for file in `ls -a $1`
do
if [ -d $1"/"$file ]
then
if [[ $file != '.' && $file != '..' ]]
then
read_dir $1"/"$file
fi
else
echo $1"/"$file
fi
done
}
#测试目录 test
read_dir test
通过curl获取HTTP返回的状态码
curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com
-I 仅输出HTTP头部信息
-m 10 最多查询10s
-o /dev/null 屏蔽原有输出信息
-s silent 模式,不输出任何东西
-w %{http_code} 控制额外输出
linux如何让历史记录不记录敏感命令
export HISTCONTROL=ignorespace
# 命令前加一个空格
echo 123
rsync脚本中免密码
/usr/bin/rsync -ratlz --rsh="/usr/bin/sshpass -p password ssh -o StrictHostKeyChecking=no -l username" src_path dest_path
gitlab ci 设置页面点击500错误
这个问题是由于gitlab重装未备份secret文件而导致的。
Enter the DB console:
For Omnibus GitLab packages:
sudo gitlab-rails dbconsole
Reset CI/CD variables
Drop the table:
DELETE FROM ci_group_variables;
DELETE FROM ci_variables;
Reset Runner registration tokens
-- Clear project tokens
UPDATE projects SET runners_token = null, runners_token_encrypted = null;
-- Clear group tokens
UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
-- Clear instance tokens
UPDATE application_settings SET runners_registration_token_encrypted = null;
-- Clear runner tokens
UPDATE ci_runners SET token = null, token_encrypted = null;
Reset pending pipeline jobs
-- Clear build tokens
UPDATE ci_builds SET token = null, token_encrypted = null;
更新配置
gitlab-ctl reconfigure
结尾
exec.sh
#!/bin/sh
base_url=http://192.168.0.1/
read_dir(){
for file in `ls -a $1`
do
if [ -d $1"/"$file ]
then
if [[ $file != '.' && $file != '..' ]]
then
read_dir $1"/"$file
fi
else
_disk_path=$1"/"$file
#echo $_disk_path
_url=$(cat "$_disk_path")
#echo $_url;
echo "$_disk_path/$_url/$base_url${_disk_path:5}"
file_code=$(curl -I -w "%{http_code}" -s -o /dev/null "$base_url${_disk_path:5}")
if [[ $file_code == 404 ]]
then
#echo "need download"
wget `cat $_disk_path` -O $1"/"$file
else
echo "$_disk_path file already exist. continue and delete"
rm -f $1"/"$file
fi
fi
done
}
read_dir $1
.gitlab-ci.yml
image: wang1010q/busybox-tools
download:
stage: test
script:
- chmod +x exec.sh
- sh exec.sh root
- cd root && rsync -t -r --rsh="/usr/bin/sshpass -p $NGINX_PASSWORD ssh -o StrictHostKeyChecking=no" . $NGINX_USERNAME@$NGINX_HOST1:~/file_domain --progress
rsync:
stage: test
script:
- sshpass -p $NGINX_PASSWORD ssh -o StrictHostKeyChecking=no $NGINX_USERNAME@$NGINX_HOST1 "export HISTCONTROL=ignorespace;cd ~/file_domain; rsync -t -r --delete --rsh=\"/usr/bin/sshpass -p $NGINX_PASSWORD ssh -o StrictHostKeyChecking=no \" . $NGINX_USERNAME@$NGINX_HOST2:~/file_domain --progress"
only:
- master