如何从命令行刷新硬盘和闪存盘(或文件系统)的缓存? [英] How to flush cache of hard-disk and flash-disk (or filesystem) from command line?

查看:749
本文介绍了如何从命令行刷新硬盘和闪存盘(或文件系统)的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个备份脚本

I'm writing a backup script which

  1. 将数据复制到备份磁盘.
  2. 刷新备份磁盘.
  3. 执行哈希完整性检查.

在我过去常做sleep(60)等待一分钟之前,内核会自动刷新数据.我认为这太过分了,所以现在我尝试sudo hdparm -F --verbose /dev/disk,但是它报告错误-HDIO_DRIVE_CMD(flushcache) failed: Invalid exchange多次.

Before I used to do sleep(60) for waiting a minute so that data is automatically flushed by the kernel. Which I guess is overkill so now I'm trying sudo hdparm -F --verbose /dev/disk but it reports error - HDIO_DRIVE_CMD(flushcache) failed: Invalid exchange multiple times.

我想知道是否有任何标准方法可以将缓存刷新到硬盘上.我认为是因为usb-creator-gtk做到了,umount做到了.

I'm wondering is there any standard way to flush the cache to hard disk. I think there is because usb-creator-gtk does it, umount does it.

我正在使用Ubuntu x64 9.10

I'm using Ubuntu x64 9.10

PS:我正在尝试避免同步" ,因为此页面说它是安全的. http://ubuntuforums.org/showthread.php?t=589975

PS: I'm trying to avoid "sync" because this page says that it is not safe. http://ubuntuforums.org/showthread.php?t=589975

推荐答案

sync是否足够?

关于您的编辑-您正在尝试避免同步,因为互联网上有人在其帖子上添加了CYA免责声明?也许我不知道同步有什么问题,但它本身值得第二篇.

regarding your edit - you are trying to avoid sync because some guy on the internet put a CYA disclaimer on his post? Maybe there is something wrong with sync of which I am unaware but that might be worth a 2nd post in itself.

仍然,从linux信息页面:

Still, from the linux info pages:

sync将内存中缓冲的所有数据写出到磁盘.这个可以 包括(但不限于)修改后的超级块,修改后的inode, 并延迟读取和写入.这必须由内核来实现. 同步程序只执行同步"系统调用.

sync writes any data buffered in memory out to disk. This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes. This must be implemented by the kernel; The sync program does nothing but exercise the 'sync' system call.

这篇关于如何从命令行刷新硬盘和闪存盘(或文件系统)的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆