fsck: New --incremental-restart option which is nice for scheduling eg, monthly incremental fsck runs in cron jobs.

This commit is contained in:
Joey Hess 2012-09-25 19:37:34 -04:00
parent 071aad8925
commit 3e297e99a3
3 changed files with 51 additions and 5 deletions

View file

@ -25,6 +25,7 @@ import Utility.FileMode
import Config
import qualified Option
import Types.Key
import Utility.HumanTime
import System.Posix.Process (getProcessID)
import Data.Time.Clock.POSIX
@ -45,8 +46,17 @@ startIncrementalOption = Option.flag ['S'] "incremental" "start an incremental f
moreIncrementalOption :: Option
moreIncrementalOption = Option.flag ['m'] "more" "continue an incremental fsck"
incrementalRestartOption :: Option
incrementalRestartOption = Option.field [] "incremental-restart" paramTime
"schedule an incremental fsck"
options :: [Option]
options = [fromOption, startIncrementalOption, moreIncrementalOption]
options =
[ fromOption
, startIncrementalOption
, moreIncrementalOption
, incrementalRestartOption
]
seek :: [CommandSeek]
seek =
@ -57,14 +67,33 @@ seek =
withIncremental :: (Incremental -> CommandSeek) -> CommandSeek
withIncremental = withValue $ do
i <- maybe (return False) (checkrestart . parseDuration)
=<< Annex.getField (Option.name incrementalRestartOption)
starti <- Annex.getFlag (Option.name startIncrementalOption)
morei <- Annex.getFlag (Option.name moreIncrementalOption)
case (starti, morei) of
(False, False) -> return NonIncremental
(True, _) -> do
case (i, starti, morei) of
(False, False, False) -> return NonIncremental
(False, True, _) -> startIncremental
(False ,False, True) -> ContIncremental <$> getStartTime
(True, _, _) ->
maybe startIncremental (return . ContIncremental . Just)
=<< getStartTime
where
startIncremental = do
recordStartTime
return StartIncremental
(False, True) -> ContIncremental <$> getStartTime
checkrestart Nothing = error "bad --incremental-restart value"
checkrestart (Just delta) = do
Annex.addCleanup "" $ do
v <- getStartTime
case v of
Nothing -> noop
Just started -> do
now <- liftIO getPOSIXTime
when (now - realToFrac started >= delta) $
resetStartTime
return True
start :: Maybe Remote -> Incremental -> FilePath -> (Key, Backend) -> CommandStart
start from inc file (key, backend) = do
@ -389,6 +418,9 @@ recordStartTime = do
showTime :: POSIXTime -> String
showTime = show
resetStartTime :: Annex ()
resetStartTime = liftIO . nukeFile =<< fromRepo gitAnnexFsckState
{- Gets the incremental fsck start time. -}
getStartTime :: Annex (Maybe EpochTime)
getStartTime = do

2
debian/changelog vendored
View file

@ -8,6 +8,8 @@ git-annex (3.20120925) UNRELEASED; urgency=low
Thanks, Justin Azoff
* New --time-limit option, makes long git-annex commands stop after
a specified amount of time.
* fsck: New --incremental-restart option which is nice for scheduling
eg, monthly incremental fsck runs in cron jobs.
-- Joey Hess <joeyh@debian.org> Mon, 24 Sep 2012 19:58:07 -0400

View file

@ -266,6 +266,18 @@ subdirectories).
the next time you fsck, you can specify --more to skip over
files that have already been checked, and continue where it left off.
The --incremental-restart option makes a new incremental fsck be
started a configurable time after the last incremental fsck was started.
Note that the current incremental fsck has to completely finish
before the restart happens.
Maybe you'd like to run a fsck for 5 hours at night, picking up each
night where it left off. You'd like this to continue until all files
have been fscked. And once it's done, you'd like a new fsck pass to start,
but no more often than once a month. Then put this in a nightly cron job:
git annex fsck --incremental-restart 30d --time-limit 5h
* unused
Checks the annex for data that does not correspond to any files present