Xen Server服务器释放磁盘空间

disk.sh

shell 复制代码
#!/bin/bash

cd /run/sr-mount/e54f0646-ae11-0457-b64f-eba4673b824c
# 全部虚拟机物理磁盘文件存储
a=$(ls -l | awk '{print $NF}' | cut -d'.' -f1)
# 使用中的虚拟机物理磁盘文件
b=$(xe vm-disk-list --multiple | grep uuid | awk '{print $NF}')

printf "%s\n" "${a[@]}" | sort > /tmp/a_sorted.txt
printf "%s\n" "${b[@]}" | sort > /tmp/b_sorted.txt

#comm -23 /tmp/b_sorted.txt /tmp/a_sorted.txt
#comm -13 /tmp/b_sorted.txt /tmp/a_sorted.txt

# 获取未使用的垃圾磁盘文件,删除,释放空间
array=($(comm -13 /tmp/b_sorted.txt /tmp/a_sorted.txt))

#echo ${#array[@]}
for i in "${array[@]}"; do
        file="$i.vhd"
        if [[ -f $file ]]; then
                du -sh $file
        fi
done

bash disk.sh | sort -rh | cat -n

以上结果可删除释放磁盘空间

相关推荐
小新讲网安11 分钟前
HTTP请求走私攻击实战:CL.TE与TE.CL绕过前端服务器全解析
服务器·前端·网络·web安全·http·架构·漏洞
桑榆4165 小时前
双系统(Windows + Ubuntu)安装流程
linux·windows·ubuntu
jerryinwuhan9 小时前
《系统部署与运维》开篇 课程介绍
运维
ltl11 小时前
实时 OS 巡礼:VxWorks、QNX、Zephyr 与 PREEMPT_RT
linux
我是谁??11 小时前
Ubuntu22.04更换清华源
linux·运维·服务器
圣殿骑士-Khtangc12 小时前
Go字符串高效拼接性能对比与底层原理分析
服务器·前端·golang
Shell运维手记12 小时前
Linux 常用基础命令学习笔记
linux·运维·笔记·学习·算法·github
朴马丁12 小时前
国际与国产PLM在精细化工赛道的布局:2026年主要厂商技术特色
大数据·运维·人工智能·流程行业plm·化工新材料
这个DBA有点耶13 小时前
数据库一体机架构演进:从硬件堆叠到软硬深度耦合
服务器·网络·数据库·硬件架构·运维开发·database·数据库架构
Elastic 中国社区官方博客13 小时前
Elasticsearch:使用 AI Agent 来创建 workflow
大数据·运维·人工智能·elasticsearch·搜索引擎·自动化·全文检索