ansible - 恢复使用 Copy 创建的备份文件
问题描述
如果使用 Copy(backup=yes)创建备份文件,例如,使用此任务:
- name: copy file
copy:
dest: path/to/dest
src: path/to/src
backup: yes
如果文件path/to/dest
已经存在,它将被移动到一个看起来像的文件中path/to/dest.12345.2006-07-08@09:10:11
有没有办法恢复它,或者获取备份文件的文件名以恢复它?
解决方案
备份文件的绝对文件名(如果生成,所以如果“更改”为真),在输出对象中返回,所以(将以下作为伪代码,因为我没有测试它):
- name: copy file
copy:
dest: path/to/dest
src: path/to/src
backup: yes
register: copy_file
- debug: var=copy_file.backup_file
- name: restore backup
copy:
dest: path/to/dest
src: copy_file.backup_file
remote_src: true
when: copy_file.changed and some condition of yours
推荐阅读
- python - 如何在图像周围添加圆形边框?
- python - 使用 Pandas 从 CSV 文件中提取值
- react-admin - 如何更新、删除、插入到 react-admin 中的管理存储?
- pdf - 在 Flutter/Dart 中将 PDF 转换为 SVG
- c - 尝试存储指向另一个指针变量的指针时出现分段错误
- html - SVG 文本边框颜色不匹配
- python - 基于权重的列表中的可变长度元素采样
- python - 如何使用 mpi4py 打开文件并分散它?
- azure-sql-database - 配置具有较低 DTU 的辅助 Azure Sql 数据库
- python - 不使用 ODBC 将 Python 连接到 SQL Server