Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1180 UpdateDB to backup previous CrawlDB

Markus Jelsma3c420450481f
diff --git a/CHANGES.txt b/CHANGES.txt
index e02ae2c1d..30fb01cd1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,7 @@
Nutch Change Log
+* NUTCH-1180 UpdateDB to backup previous CrawlDB (markus)
+
* NUTCH-1173 DomainStats doesn't count db_not_modified (markus)
* NUTCH-1155 Host/domain limit in generator is generate.max.count+1 (markus)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index d673fc0bb..25f3d1c36 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -403,6 +403,15 @@
</description>
</property>
+<property>
+ <name>db.preserve.backup</name>
+ <value>true</value>
+ <description>If true, updatedb will keep a backup of the previous CrawlDB
+ version in the old directory. In case of disaster, one can rename old to
+ current and restore the CrawlDB to its previous state.
+ </description>
+</property>
+
<property>
<name>db.update.purge.404</name>
<value>false</value>
diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.java
index e442c2133..45880ed41 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDb.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java
@@ -146,6 +146,8 @@ public class CrawlDb extends Configured implements Tool {
}
public static void install(JobConf job, Path crawlDb) throws IOException {
+ boolean preserveBackup = job.getBoolean("db.preserve.backup", true);
+
Path newCrawlDb = FileOutputFormat.getOutputPath(job);
FileSystem fs = new JobClient(job).getFs();
Path old = new Path(crawlDb, "old");
@@ -156,7 +158,7 @@ public class CrawlDb extends Configured implements Tool {
}
fs.mkdirs(crawlDb);
fs.rename(newCrawlDb, current);
- if (fs.exists(old)) fs.delete(old, true);
+ if (!preserveBackup && fs.exists(old)) fs.delete(old, true);
Path lock = new Path(crawlDb, LOCK_NAME);
LockUtil.removeLockFile(fs, lock);
}