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

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

相关推荐
你好潘先生4 小时前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
orion5715 小时前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站20 小时前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
程序员老赵1 天前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术1 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式