Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush cache of hard-disk and flash-disk (or filesystem) from command line?

Tags:

linux

ubuntu

I'm writing a backup script which

  1. Copies the data to backup disk.
  2. Flushes the backup disk.
  3. Performs a hash integrity check.

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.

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.

I'm using Ubuntu x64 9.10

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

like image 844
Vikrant Chaudhary Avatar asked Mar 05 '10 02:03

Vikrant Chaudhary


People also ask

What is flush disk?

Writing a buffer to disk is called buffer flushing . When a user thread modifies data in a buffer, it marks the buffer as dirty . When the database server flushes the buffer to disk, it subsequently marks the buffer as not dirty and allows the data in the buffer to be overwritten.

What is flush Linux?

DESCRIPTION. The flush(8) server maintains a record of deferred mail by destination. This information is used to improve the performance of the SMTP ETRN request, and of its command-line equivalent, "sendmail -qR" or "postqueue -f". This program expects to be run from the master(8) process manager.


1 Answers

Does sync suffice?

Edit: 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.

Still, from the linux info pages:

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.

like image 172
Duck Avatar answered Sep 21 '22 04:09

Duck