问题描述
我正在编写一个备份脚本
I'm writing a backup script which
- 将数据复制到备份磁盘.
- 刷新备份磁盘.
- 执行哈希完整性检查.
在我过去常做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 caninclude (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.
这篇关于如何从命令行刷新硬盘和闪存盘(或文件系统)的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!