我正在root用户下设置cronjob来通过Ansible备份我的Jenkins服务器。 cronjob有望每周运行从我的本地文件夹复制的shell脚本。
下面的代码是我产生的
- name: copy backup scripts to the server
copy:
src: ./../../scripts/swift-backup.sh
dest: /scripts/swift-backup.sh
owner: root
group: root
mode: 777
- name: check if file exists
file:
path: /scripts/swift-backup.sh
state: file
- name: Automatic backup the VM
cron:
name: "Automatic backup to swift with rclone"
minute: "0"
hour: "0"
weekday: "0"
job: "sh /scripts/swift-backup.sh"
check if file exists
成功找到了文件。我什至在服务器上手动找到了脚本。但是,这是我从cron作业中获得的日志:
sh: 0: Can't open scripts/swift-backup.sh
当我执行整个任务时,这是什么问题?这是脚本中的代码:
#!/usr/bin/env bash
. ./../openrc-monsoon3-MLOps
while [ $(rclone lsd monsoon:jenkins_backup_test | wc -l) -ge 3 ]
do
# find and remove oldest backup folder
rclone delete monsoon:jenkins_backup_test/$(rclone lsd monsoon:jenkins_backup_test | head -1 | awk '{print $NF}')
done
# Push file to monsoon
rclone copy backup/ monsoon:jenkins_backup_test -L
rm backup/* -rf