您现在的位置是: 网站首页 >Shell >Linux应用服务配置 Shell
Clonezilla 备份还原过程推送日志到 syslog
admin2024年7月18日 22:08
【Clonezilla | Linux | Shell
】
35人已围观
Linux应用服务配置简介 各类Linux软件安装配置
Clonezilla 备份、还原过程中,系统的运行日志只能显示到客户端显示器上,如果出现错误,无法在服务端查询到对应的日志,一是故障判断不太方便;另一方面,实现日志推送,也可以将 Clonezilla 运行进度上传到服务端,监控备份还原的进度。 以下为备份、还原过程中常见的节点,可以在该命令下方添加推送 syslog 的指令。 ![BLOG_20240718_221221_74](/media/blog/images/2024/07/BLOG_20240718_221221_74.png "博客图集BLOG_20240718_221221_74.png") ## 1、系统备份 ### ✓空间不足或权限问题(line: 1137) ```bash # usr\share\drbl\sbin\ocs-functions if [ "$ok_c" = "no" ]; then [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE echo "$msg_disk_is_full_or_permission_issue: $tgt_dir" | tee --append ${OCS_LOGFILE} [ -n "$prompt_msg" ] && echo $prompt_msg [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE} [ -f "$diskfull_test" ] && rm -f $diskfull_test echo -n "$msg_press_enter_to_continue..." read # Saving mode, always copy error log to image dir. copy_error_log exit 1 fi ``` ```bash # usr\share\drbl\lang\bash\zh_CN.UTF-8 msg_disk_is_full_or_permission_issue='空间不足或权限问题,当前目录无法写入:' # Clonezilla运行过程中提示 空间不足或权限问题,当前目录无法写入: /home/partimag ``` ### ✓开始保存镜像(line: 1774) ```bash # usr\share\drbl\sbin\ocs-functions echo "Starting saving $source_dev as $tgt_dir/${tgt_file}.XXX..." | tee --append ${OCS_LOGFILE} ``` ### ✓完成保存镜像(line: 1289、1471、1531、1715) ```bash # usr\share\drbl\sbin\ocs-functions save_part_by_ntfsclone() { # ... echo "Finished saving $source_dev as $tgt_dir/${tgt_file}.ntfs-img" } # end of save_part_by_ntfsclone save_part_by_partclone() { # ... if [ $rc -eq 0 ]; then echo $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} fi return $rc } # end of save_part_by_partclone save_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_partimage save_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) ```bash # usr\share\drbl\sbin\ocs-functions echo $msg_delimiter_star_line | tee --append ${OCS_LOGFILE} if [ "$rc" -ne 0 ]; then [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE echo "Failed to save partition $source_dev." | tee --append ${OCS_LOGFILE} [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "$msg_press_enter_to_continue..." read # Saving mode, always copy error log to image dir. copy_error_log fi ``` ```bash # Clonezilla运行过程中提示 Failed to save partition /dev/nvme0n1p3. ``` ### ✓镜像保存/未保存成功+完成保存(line: 8760) ```bash # usr\share\drbl\sbin\ocs-functions if [ "$rc_task_savedisk" -eq 0 ]; then [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "$msg_this_image_saved_successfully: $target_dir" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL else [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE echo "$msg_this_image_not_saved_correctly" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL fi echo "End of savedisk job for image $target_dir." | tee --append $OCS_LOGFILE ``` ```bash # 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) ```bash # usr\share\drbl\sbin\ocs-functions unicast_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_partimage unicast_restore_by_ntfsclone() { # ... echo $msg_delimiter_star_line echo "Starting unicast restoring image ${target_d##*/} to $part..." # ... } # end of unicast_restore_by_ntfsclone unicast_restore_by_partclone() { # ... echo $msg_delimiter_star_line echo "Starting unicast restoring image ${target_d##*/} to $part..." | tee --append ${OCS_LOGFILE} # ... } # end of unicast_restore_by_partclone unicast_restore_by_dd() { # ... echo $msg_delimiter_star_line echo "Starting unicast restoring image ${target_d##*/} to $part..." # ... } # end of unicast_restore_by_dd ``` ### ✓完成还原镜像(line: 6185) ```bash # usr\share\drbl\sbin\ocs-functions echo $msg_delimiter_star_line # time_elapsed, time_elapsed_in_min and speed are global variables # get the cat program: cat, zcat or bzcat if [ -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 partimage clean_filesystem_header_in_dev $part unicast_restore_by_partimage elif [ -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 ntfsclone clean_filesystem_header_in_dev $part unicast_restore_by_ntfsclone elif is_partclone_image $target_d $img_file; then # The saved image is from partclone clean_filesystem_header_in_dev $part unicast_restore_by_partclone elif is_dd_image $target_d $img_file; then # The saved image is from dd clean_filesystem_header_in_dev $part unicast_restore_by_dd fi echo "Finished unicast restoring image ${target_d##*/} to $part." | tee --append ${OCS_LOGFILE} sleep 1 ``` ### ✓完成还原(line: 9349) ```bash # usr\share\drbl\sbin\ocs-functions echo "Running: task_restoreparts \"$target_dir\" \"$target_parts\" \"$port\"" >> $OCS_LOGFILE task_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) ```bash # usr\sbin\ocs-sr echo "Starting $0 at "$(LC_ALL=C date +%F' '%T' '%Z)"..." | tee --append ${OCS_LOGFILE} ``` ### ✓完成ocs-sr(line: 1756) ```bash # usr\sbin\ocs-sr echo "Ending $0 at $(LC_ALL=C date +%F' '%T' '%Z)..." | tee --append ${OCS_LOGFILE} exit 0 ``` ```bash # Clonezilla运行过程中提示 Ending /usr/sbin/ocs-sr at 2024-01-01 13:13:13 UTC... ``` ### ✓完成后重启(line: 96) ```bash # usr\share\drbl\sbin\ocs-functions reboot) ocs-park-disks echo -n 'Will reboot... '; countdown 5 reboot $HALT_REBOOT_OPT ;; ``` ```bash # Clonezilla运行过程中提示 Will reboot... 5 4 3 2 1 ``` ## 4、服务端日志收集 <mark>以上 Clonezilla 文件中,通过 shell 脚本去修改文本,添加日志命令,最终结果如下:</mark> ### 1)备份日志 ```log 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 ``` ### 还原日志 ```log 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 ↑↑↑ ```
很赞哦! (0)
相关文章
文章交流
- emoji