Exclude seeds from backup (#3950)

This commit is contained in:
rorp 2022-01-04 07:04:14 -08:00 committed by GitHub
parent 524c5212e0
commit 5de325e7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -18,10 +18,12 @@ import org.bitcoins.rpc.config.BitcoindRpcAppConfig
import org.bitcoins.tor.config.TorAppConfig
import org.bitcoins.wallet.config.WalletAppConfig
import java.io.IOException
import java.nio.file.{Files, Path, Paths}
import java.util.concurrent.TimeUnit
import scala.concurrent.Future
import scala.concurrent.duration.{DurationInt, FiniteDuration}
import scala.util.Try
/** A unified config class for all submodules of Bitcoin-S
* that accepts configuration. Thanks to implicit definitions
@ -155,7 +157,7 @@ case class BitcoinSAppConfig(
/** Zips $HOME/.bitcoin-s
*/
def zipDatadir(target: Path): Path =
def zipDatadir(target: Path): Try[Path] =
BitcoinSAppConfig.zipDatadir(directory, target)
}
@ -259,21 +261,30 @@ object BitcoinSAppConfig extends Logging {
conf.bitcoindRpcConf
}
def zipDatadir(source: Path, target: Path): Path = {
def zipDatadir(source: Path, target: Path): Try[Path] = Try {
if (Files.exists(target)) {
throw new IOException(
s"Cannot zip datadir. Target file already exists: $target")
}
val temp = Files.createTempDirectory(source, "backup")
try {
// we don't want to store chaindb.sqlite as these databases are huge
// skip logs and binaries as these can be large as well
val tempRE = (".*" + temp.getFileName + "$").r
val tempRE = (".*/" + temp.getFileName + "/.*").r
FileUtil.copyDirectory(source = source,
target = temp,
fileNameFilter = Vector(".*.sqlite$".r,
".*bitcoin-s.log$".r,
".*/tor/.*".r,
".*/binaries/.*".r,
".*.zip$".r,
tempRE))
FileUtil.copyDirectory(
source = source,
target = temp,
fileNameFilter = Vector(".*.sqlite$".r,
".*.sqlite-shm$".r,
".*.sqlite-wal$".r,
".*bitcoin-s.log$".r,
".*/seeds/.*".r,
".*/tor/.*".r,
".*/binaries/.*".r,
".*.zip$".r,
tempRE)
)
SQLiteUtil.backupDirectory(source = source,
target = temp,

View File

@ -19,6 +19,7 @@ import upickle.default._
import scala.collection.mutable
import scala.concurrent.Future
import scala.util.{Failure, Success}
case class CoreRoutes()(implicit system: ActorSystem, config: BitcoinSAppConfig)
extends ServerRoute {
@ -225,8 +226,10 @@ case class CoreRoutes()(implicit system: ActorSystem, config: BitcoinSAppConfig)
withValidServerCommand(ZipDataDir.fromJsArr(arr)) {
case ZipDataDir(path) =>
complete {
config.zipDatadir(path)
Server.httpSuccess(ujson.Null)
config.zipDatadir(path) match {
case Success(_) => Server.httpSuccess(ujson.Null)
case Failure(ex) => Server.httpError(ex.getMessage)
}
}
}
}