We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
很多服务比如 jenkins, qbittorrent, jellyfin 等等都是有状态服务,如何定期将这些数据备份到 NAS 上呢?
有几种方法:
就不谈了。
需要创建忙忙多的 shell 脚本,然后在对应机器维护好 crontab 任务。
事实上我最开始就是用这种方法的:
每个 sh 的文件内容大致如下:
#!/bin/sh APPNAME=uptime-kuma ARCHIVE=$APPNAME-$(date +%Y%m%d).tar.gz APPPATH=/home/ubuntu/uptime-kuma/ STORAGE=/mnt/ServerBackups/sHan/$APPNAME/ cd $APPPATH tar czvPf $ARCHIVE * rsync $ARCHIVE $STORAGE rm -rf $ARCHIVE
缺点是要创建很多的 shell,crontab 还需要处理用户权限问题,总不能所有的备份都用 root 用户来进行吧,不太安全。
注意前提,应用必须部署在 k8s 上。
可以利用 helm 模板,内容如下:
{{- range .Values.backupTasks }} apiVersion: batch/v1 kind: CronJob metadata: name: {{ .name }} spec: schedule: "{{ .schedule }}" jobTemplate: spec: template: spec: restartPolicy: OnFailure containers: - name: backup-container image: ghcr.io/instrumentisto/rsync-ssh:alpine3.20 command: ["/bin/sh"] args: [ "-c", "ssh -t -o StrictHostKeyChecking=no -i /etc/secret-volume/{{ .privateKeyName }} {{ .target.server }} 'mkdir -p {{ .target.path }}'; rsync -e 'ssh -o StrictHostKeyChecking=no -i /etc/secret-volume/{{ .privateKeyName }}' -avz /data/ {{ .target.server }}:{{ .target.path }}", ] volumeMounts: - name: secret-volume mountPath: /etc/secret-volume readOnly: true - name: pvc-to-backup mountPath: /data volumes: - name: secret-volume secret: secretName: {{ .secretName }} defaultMode: 0400 - name: pvc-to-backup persistentVolumeClaim: claimName: {{ .pvc }} --- {{- end }}
让 GPT 帮忙把 yaml 翻译为人话,做了这些事:
然后创建 values.yaml 文件,我这里放几个自己的备份内容:
# Helm template path: ../backup-cronjob # Run command: helm upgrade backup-task ./backup-cronjob -f ./backup_values.yaml backupTasks: - name: backup-jenkins schedule: "0 3 * * *" pvc: jenkins-pvc-local secretName: backup-privatekey privateKeyName: id_rsa target: server: [email protected] path: /share/ServerBackups/app/jenkins - name: backup-vaultwarden schedule: "0 3 * * *" pvc: vaultwarden-pvc-local secretName: backup-privatekey privateKeyName: id_rsa target: server: [email protected] path: /share/ServerBackups/app/vaultwarden - name: backup-homeassistant-config schedule: "0 3 * * *" pvc: homeassistant-config-pvc-local secretName: backup-privatekey privateKeyName: id_rsa target: server: [email protected] path: /share/ServerBackups/app/homeassistant/config
最后执行 helm upgrade 命令来让 cronjob 任务生效:
helm upgrade
helm upgrade backup-task ./backup-cronjob -f ./backup_values.yaml
效果如下:
ziyuan@pve-ubuntu:~/k8s$ kubectl get cronjob NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE backup-jenkins 0 3 * * * False 0 14h 12d backup-vaultwarden 0 3 * * * False 0 14h 12d backup-homeassistant-ssh 0 3 * * * False 0 14h 12d ziyuan@pve-ubuntu:~/k8s$ kubectl get pod | grep backup backup-vaultwarden-28805460-4blkd 0/1 Completed 0 14h backup-jenkins-28805460-zznwn 0/1 Completed 0 14h backup-homeassistant-config-28805976-rff2g 0/1 Completed 0 6h2m # 远端 NAS [/share/ServerBackups/app] # ll total 48K drwxrwx--- 6 admin administrators 4.0K 2024-10-08 16:54 ./ drwxrwxrwx 12 admin administrators 4.0K 2024-09-12 10:38 ../ drwxrwx--- 3 admin administrators 4.0K 2024-10-08 11:33 homeassistant/ drwxrwx--- 3 admin administrators 4.0K 2024-10-08 16:54 jellyfin/ drwxrwxr-x 21 hanziyuan my-system 4.0K 2024-09-26 17:19 jenkins/ drwxr-xr-x 6 hanziyuan my-system 4.0K 2024-06-29 10:26 vaultwarden/
因为备份脚本或者 yaml 会涉及敏感信息,这里就不贴出来仓库地址了。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
前言
很多服务比如 jenkins, qbittorrent, jellyfin 等等都是有状态服务,如何定期将这些数据备份到 NAS 上呢?
有几种方法:
方法详情
方法 1
就不谈了。
方法 2
需要创建忙忙多的 shell 脚本,然后在对应机器维护好 crontab 任务。
事实上我最开始就是用这种方法的:
每个 sh 的文件内容大致如下:
缺点是要创建很多的 shell,crontab 还需要处理用户权限问题,总不能所有的备份都用 root 用户来进行吧,不太安全。
方法 3
注意前提,应用必须部署在 k8s 上。
可以利用 helm 模板,内容如下:
让 GPT 帮忙把 yaml 翻译为人话,做了这些事:
然后创建 values.yaml 文件,我这里放几个自己的备份内容:
最后执行
helm upgrade
命令来让 cronjob 任务生效:效果如下:
其他
因为备份脚本或者 yaml 会涉及敏感信息,这里就不贴出来仓库地址了。
The text was updated successfully, but these errors were encountered: