Clonezilla 备份、还原过程中,系统的运行日志只能显示到客户端显示器上,如果出现错误,无法在服务端查询到对应的日志,一是故障判断不太方便;另一方面,实现日志推送,也可以将 Clonezilla 运行进度上传到服务端,监控备份还原的进度。
以下为备份、还原过程中常见的节点,可以在该命令下方添加推送 syslog 的指令。
1、系统备份
✓空间不足或权限问题(line: 1137)
# usr\share\drbl\sbin\ocs-functionsif [ "$ok_c" = "no" ]; then[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILUREecho "$msg_disk_is_full_or_permission_issue: $tgt_dir" | tee --append ${OCS_LOGFILE}[ -n "$prompt_msg" ] && echo $prompt_msg[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMALecho "$msg_program_stop!" | tee --append ${OCS_LOGFILE}[ -f "$diskfull_test" ] && rm -f $diskfull_testecho -n "$msg_press_enter_to_continue..."read# Saving mode, always copy error log to image dir.copy_error_logexit 1fi
# usr\share\drbl\lang\bash\zh_CN.UTF-8
msg_disk_is_full_or_permission_issue='空间不足或权限问题,当前目录无法写入:'# Clonezilla运行过程中提示
空间不足或权限问题,当前目录无法写入: /home/partimag
✓开始保存镜像(line: 1774)
# usr\share\drbl\sbin\ocs-functionsecho "Starting saving $source_dev as $tgt_dir/${tgt_file}.XXX..." | tee --append ${OCS_LOGFILE}
✓完成保存镜像(line: 1289、1471、1531、1715)
# usr\share\drbl\sbin\ocs-functionssave_part_by_ntfsclone() {# ...echo "Finished saving $source_dev as $tgt_dir/${tgt_file}.ntfs-img"
} # end of save_part_by_ntfsclonesave_part_by_partclone() {# ...if [ $rc -eq 0 ]; thenecho $msg_delimiter_star_line | tee --append ${OCS_LOGFILE}echo "Finished saving $source_dev as $tgt_dir/$(to_filename ${tgt_file}).${fs_pre}-img.${comp_suf}" | tee --append ${OCS_LOGFILE}fireturn $rc
} # end of save_part_by_partclonesave_part_by_partimage() {# ...echo "Finished saving $source_dev as $tgt_dir/${tgt_file}.XXX" | tee --append ${OCS_LOGFILE}return $rc
} # end of save_part_by_partimagesave_part_by_dd() {# ...echo "Finished saving $source_dev as $tgt_dir/$(to_filename ${tgt_file}).dd-img" | tee --append ${OCS_LOGFILE}return $rc
} # end of save_part_by_dd
✓镜像保存报错(line: 1800)
# usr\share\drbl\sbin\ocs-functionsecho $msg_delimiter_star_line | tee --append ${OCS_LOGFILE}if [ "$rc" -ne 0 ]; then[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILUREecho "Failed to save partition $source_dev." | tee --append ${OCS_LOGFILE}[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMALecho "$msg_press_enter_to_continue..."read# Saving mode, always copy error log to image dir.copy_error_logfi
# Clonezilla运行过程中提示
Failed to save partition /dev/nvme0n1p3.
✓镜像保存/未保存成功+完成保存(line: 8760)
# usr\share\drbl\sbin\ocs-functionsif [ "$rc_task_savedisk" -eq 0 ]; then[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNINGecho "$msg_this_image_saved_successfully: $target_dir"[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMALelse[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILUREecho "$msg_this_image_not_saved_correctly"[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMALfiecho "End of savedisk job for image $target_dir." | tee --append $OCS_LOGFILE
# usr\share\drbl\lang\bash\zh_CN.UTF-8
msg_this_image_saved_successfully='镜像保存成功'
msg_this_image_not_saved_correctly='镜像未保存成功'# Clonezilla运行过程中提示
End of savedisk job for image /home/partimag/2023-07-09-img.
2、系统还原
✓开始还原镜像(line: 5519、5589、5691、5812)
# usr\share\drbl\sbin\ocs-functionsunicast_restore_by_partimage() {# ...echo $msg_delimiter_star_line | tee --append ${OCS_LOGFILE}echo "Starting unicast restoring image ${target_d##*/} to $part..." | tee --append ${OCS_LOGFILE}# ...
} # end of unicast_restore_by_partimageunicast_restore_by_ntfsclone() {# ...echo $msg_delimiter_star_lineecho "Starting unicast restoring image ${target_d##*/} to $part..."# ...
} # end of unicast_restore_by_ntfscloneunicast_restore_by_partclone() {# ...echo $msg_delimiter_star_lineecho "Starting unicast restoring image ${target_d##*/} to $part..." | tee --append ${OCS_LOGFILE}# ...
} # end of unicast_restore_by_partcloneunicast_restore_by_dd() {# ...echo $msg_delimiter_star_lineecho "Starting unicast restoring image ${target_d##*/} to $part..."# ...
} # end of unicast_restore_by_dd
✓完成还原镜像(line: 6185)
# usr\share\drbl\sbin\ocs-functionsecho $msg_delimiter_star_line# time_elapsed, time_elapsed_in_min and speed are global variables# get the cat program: cat, zcat or bzcatif [ -f "$target_d/$img_file.000" -o \-n "$(ls $target_d/$img_file.aa* 2>/dev/null)" -o \-f "$target_d/$img_file" ]; then# The saved image is from partimageclean_filesystem_header_in_dev $partunicast_restore_by_partimageelif [ -f "$target_d/$img_file.ntfs-img" -o \-n "$(ls $target_d/$img_file.ntfs-img.aa* 2>/dev/null)" ]; then# The saved image is from ntfscloneclean_filesystem_header_in_dev $partunicast_restore_by_ntfscloneelif is_partclone_image $target_d $img_file; then# The saved image is from partcloneclean_filesystem_header_in_dev $partunicast_restore_by_partcloneelif is_dd_image $target_d $img_file; then# The saved image is from ddclean_filesystem_header_in_dev $partunicast_restore_by_ddfiecho "Finished unicast restoring image ${target_d##*/} to $part." | tee --append ${OCS_LOGFILE}sleep 1
✓完成还原(line: 9349)
# usr\share\drbl\sbin\ocs-functionsecho "Running: task_restoreparts \"$target_dir\" \"$target_parts\" \"$port\"" >> $OCS_LOGFILEtask_restoreparts "$target_dir" "$target_parts" "$port"echo "End of restoredisk job for image $target_dir." | tee --append $OCS_LOGFILE
3、ocs-sr通用
✓开始ocs-sr(line: 1116)
# usr\sbin\ocs-srecho "Starting $0 at "$(LC_ALL=C date +%F' '%T' '%Z)"..." | tee --append ${OCS_LOGFILE}
✓完成ocs-sr(line: 1756)
# usr\sbin\ocs-srecho "Ending $0 at $(LC_ALL=C date +%F' '%T' '%Z)..." | tee --append ${OCS_LOGFILE}
exit 0
# Clonezilla运行过程中提示
Ending /usr/sbin/ocs-sr at 2024-01-01 13:13:13 UTC...
✓完成后重启(line: 96)
# usr\share\drbl\sbin\ocs-functionsreboot)ocs-park-disksecho -n 'Will reboot... '; countdown 5reboot $HALT_REBOOT_OPT;;
# Clonezilla运行过程中提示
Will reboot... 5 4 3 2 1
4、服务端日志收集
以上 Clonezilla 文件中,通过 shell 脚本去修改文本,添加日志命令,最终结果如下:
1)备份日志
2024-07-18 18:53:41 | INFO | 192.168.100.161 ipxe: Downloaded "menu.ipxe"
2024-07-18 18:53:41 | INFO | 192.168.100.161 ipxe: Executing "menu.ipxe"
2024-07-18 18:53:45 | INFO | 192.168.100.161 ipxe: Downloaded "vmlinuz"
2024-07-18 18:53:47 | INFO | 192.168.100.161 ipxe: Downloaded "initrd.img"
2024-07-18 18:53:47 | INFO | 192.168.100.161 ipxe: Executing "vmlinuz"
2024-07-18 18:54:26 | INFO | 192.168.100.163 clonezilla: Mounting samba, will mount //192.168.100.100/imgman to /home/partimag by admin
2024-07-18 18:54:26 | INFO | 192.168.100.163 clonezilla: Mount type cifs, size 146.9G, used 5%, avail 139.1G
2024-07-18 18:54:26 | INFO | 192.168.100.163 clonezilla: Mount success, /home/partimag already 3 images
2024-07-18 18:54:33 | INFO | 192.168.100.163 clonezilla: Start execute clonezilla backup image script ↓↓↓
2024-07-18 18:54:33 | INFO | 192.168.100.163 clonezilla: Select disk order: nvme ssd(100G) -> sata ssd(100G) -> sata hdd(400G)
2024-07-18 18:54:39 | INFO | 192.168.100.163 clonezilla: List disks nvme0n1(type ssd, model VMware Virtual NVMe Disk, size 172G)
2024-07-18 18:54:40 | INFO | 192.168.100.163 clonezilla: Select disk is nvme0n1
2024-07-18 18:54:40 | INFO | 192.168.100.163 clonezilla: Backup image name is (from server, it may be empty)
2024-07-18 18:54:47 | INFO | 192.168.100.163 clonezilla: Backup image name is img_01_top(actual saved image name)
2024-07-18 18:54:47 | INFO | 192.168.100.163 clonezilla: Start backup disk nvme0n1 to image img_01_top
2024-07-18 18:54:55 | INFO | 192.168.100.163 clonezilla: Starting /usr/sbin/ocs-sr at 2024-07-18 10:54:55 UTC
2024-07-18 18:55:06 | INFO | 192.168.100.163 clonezilla: Starting saving /dev/nvme0n1p1 as /home/partimag/img_01_top/nvme0n1p1.XXX
2024-07-18 18:55:21 | INFO | 192.168.100.163 clonezilla: Finished saving /dev/nvme0n1p1 as /home/partimag/img_01_top/nvme0n1p1.xfs-ptcl-img.gz by partclone
2024-07-18 18:55:23 | INFO | 192.168.100.163 clonezilla: Starting saving /dev/almalinux/root as /home/partimag/img_01_top/almalinux-root.XXX
2024-07-18 18:56:23 | INFO | 192.168.100.163 clonezilla: Finished saving /dev/almalinux/root as /home/partimag/img_01_top/almalinux-root.xfs-ptcl-img.gz by partclone
2024-07-18 18:56:23 | INFO | 192.168.100.163 clonezilla: Image img_01_top saved successfully
2024-07-18 18:56:23 | INFO | 192.168.100.163 clonezilla: End of savedisk job for image img_01_top
2024-07-18 18:56:32 | INFO | 192.168.100.163 clonezilla: Finish restore or backup, reboot pc ↑↑↑
2024-07-18 18:56:33 | INFO | 192.168.100.163 clonezilla: Ending /usr/sbin/ocs-sr at 2024-07-18 10:56:32 UTC
还原日志
2024-07-18 19:24:40 | INFO | 192.168.100.161 ipxe: Downloaded "menu.ipxe"
2024-07-18 19:24:40 | INFO | 192.168.100.161 ipxe: Executing "menu.ipxe"
2024-07-18 19:25:03 | INFO | 192.168.100.161 ipxe: Downloaded "vmlinuz"
2024-07-18 19:25:04 | INFO | 192.168.100.161 ipxe: Downloaded "initrd.img"
2024-07-18 19:25:04 | INFO | 192.168.100.161 ipxe: Executing "vmlinuz"
2024-07-18 19:25:34 | INFO | 192.168.100.164 clonezilla: Mounting samba, will mount //192.168.100.100/images to /home/partimag by image
2024-07-18 19:25:34 | INFO | 192.168.100.164 clonezilla: Mount type cifs, size 146.9G, used 5%, avail 139.1G
2024-07-18 19:25:35 | INFO | 192.168.100.164 clonezilla: Mount success, /home/partimag already 3 images
2024-07-18 19:25:41 | INFO | 192.168.100.164 clonezilla: Start execute clonezilla restore image script ↓↓↓
2024-07-18 19:25:42 | INFO | 192.168.100.164 clonezilla: Select disk order: nvme ssd(100G) -> sata ssd(100G) -> sata hdd(400G)
2024-07-18 19:25:47 | INFO | 192.168.100.164 clonezilla: List disks nvme0n1(type ssd, model VMware Virtual NVMe Disk, size 172G)
2024-07-18 19:25:48 | INFO | 192.168.100.164 clonezilla: Select disk is nvme0n1
2024-07-18 19:25:48 | INFO | 192.168.100.164 clonezilla: Backup image name is (from server, it may be empty)
2024-07-18 19:25:55 | INFO | 192.168.100.164 clonezilla: Start restore image img_01_top to disk nvme0n1
2024-07-18 19:26:03 | INFO | 192.168.100.164 clonezilla: Starting /usr/sbin/ocs-sr at 2024-07-18 11:26:03 UTC
2024-07-18 19:26:19 | INFO | 192.168.100.164 clonezilla: Starting restoring image img_01_top to /dev/nvme0n1p1 by partclone
2024-07-18 19:26:26 | INFO | 192.168.100.164 clonezilla: Finished restoring image img_01_top to /dev/nvme0n1p1
2024-07-18 19:26:33 | INFO | 192.168.100.164 clonezilla: Starting restoring image img_01_top to /dev/almalinux/root by partclone
2024-07-18 19:26:59 | INFO | 192.168.100.164 clonezilla: Finished restoring image img_01_top to /dev/almalinux/root
2024-07-18 19:27:22 | INFO | 192.168.100.164 clonezilla: End of restoredisk job for image img_01_top
2024-07-18 19:27:27 | INFO | 192.168.100.164 clonezilla: Finish restore or backup, reboot pc ↑↑↑