Bitcoin Forum
May 03, 2024, 04:02:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Backup bitcoind wallet for servers example.  (Read 1936 times)
cheako911 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
February 26, 2015, 11:11:55 PM
 #1

Replace the two occurrences of YOUREMAIL.

Code:
#!/usr/bin/env perl

use common::sense;

use Fcntl qw(O_RDONLY O_NONBLOCK);
use POSIX qw(mkfifo);
use File::Temp qw(mktemp);
use File::Copy qw(copy);

my ( undef, $api ) = do '/home/btc/.bitcoin/bitcoin.PL';

my @fh;
my $unopened_file = mktemp("/home/btc/.backup${$}XXXXX");
$SIG{INT} = sub { die };
END { unlink $unopened_file }

mkfifo( $unopened_file, 0600 ) || die "mkfifo $unopened_file failed: $!";

sysopen( $fh[0], $unopened_file, O_RDONLY | O_NONBLOCK )
  || die "open $unopened_file failed: $!";

open( $fh[1],
'|gpg --batch --trust-model always -e -a -r "YOUREMAIL"|mail -s Bitcoin_Backup YOUREMAIL'
) || die "|gpg|mail failed: $!";

$api->call( 'dumpwallet', "$unopened_file" );

copy($fh[0],$fh[1]) || die "copy $unopened_file |gpg|mail failed: $!";

bitcoin.PL contains.
Code:
use Finance::Bitcoin;
my $wallet = Finance::Bitcoin::Wallet->new(
'http://bitcoinrpc:blahblahblah@127.0.0.1:8332/'
);
( $wallet, $wallet->api );
1714708979
Hero Member
*
Offline Offline

Posts: 1714708979

View Profile Personal Message (Offline)

Ignore
1714708979
Reply with quote  #2

1714708979
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714708979
Hero Member
*
Offline Offline

Posts: 1714708979

View Profile Personal Message (Offline)

Ignore
1714708979
Reply with quote  #2

1714708979
Report to moderator
1714708979
Hero Member
*
Offline Offline

Posts: 1714708979

View Profile Personal Message (Offline)

Ignore
1714708979
Reply with quote  #2

1714708979
Report to moderator
1714708979
Hero Member
*
Offline Offline

Posts: 1714708979

View Profile Personal Message (Offline)

Ignore
1714708979
Reply with quote  #2

1714708979
Report to moderator
ca333
Hero Member
*****
Offline Offline

Activity: 520
Merit: 522


Developer - EthicHacker - BTC enthusiast


View Profile
March 05, 2015, 04:06:50 PM
 #2

Replace the two occurrences of YOUREMAIL.

Code:
#!/usr/bin/env perl

use common::sense;

use Fcntl qw(O_RDONLY O_NONBLOCK);
use POSIX qw(mkfifo);
use File::Temp qw(mktemp);
use File::Copy qw(copy);

my ( undef, $api ) = do '/home/btc/.bitcoin/bitcoin.PL';

my @fh;
my $unopened_file = mktemp("/home/btc/.backup${$}XXXXX");
$SIG{INT} = sub { die };
END { unlink $unopened_file }

mkfifo( $unopened_file, 0600 ) || die "mkfifo $unopened_file failed: $!";

sysopen( $fh[0], $unopened_file, O_RDONLY | O_NONBLOCK )
  || die "open $unopened_file failed: $!";

open( $fh[1],
'|gpg --batch --trust-model always -e -a -r "YOUREMAIL"|mail -s Bitcoin_Backup YOUREMAIL'
) || die "|gpg|mail failed: $!";

$api->call( 'dumpwallet', "$unopened_file" );

copy($fh[0],$fh[1]) || die "copy $unopened_file |gpg|mail failed: $!";

bitcoin.PL contains.
Code:
use Finance::Bitcoin;
my $wallet = Finance::Bitcoin::Wallet->new(
'http://bitcoinrpc:blahblahblah@127.0.0.1:8332/'
);
( $wallet, $wallet->api );


thank you for sharing. i extended your script with parameters and config-file.
will upload/share when finished. will try add ssl config for wallet-connection too.

greetings!

this space is available (free) for humanitarian nonprofit organizations - please contact me
cheako911 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
March 05, 2015, 06:46:34 PM
 #3

Replace the two occurrences of YOUREMAIL.

Code:
#!/usr/bin/env perl

use common::sense;

use Fcntl qw(O_RDONLY O_NONBLOCK);
use POSIX qw(mkfifo);
use File::Temp qw(mktemp);
use File::Copy qw(copy);

my ( undef, $api ) = do '/home/btc/.bitcoin/bitcoin.PL';

my @fh;
my $unopened_file = mktemp("/home/btc/.backup${$}XXXXX");
$SIG{INT} = sub { die };
END { unlink $unopened_file }

mkfifo( $unopened_file, 0600 ) || die "mkfifo $unopened_file failed: $!";

sysopen( $fh[0], $unopened_file, O_RDONLY | O_NONBLOCK )
  || die "open $unopened_file failed: $!";

open( $fh[1],
'|gpg --batch --trust-model always -e -a -r "YOUREMAIL"|mail -s Bitcoin_Backup YOUREMAIL'
) || die "|gpg|mail failed: $!";

$api->call( 'dumpwallet', "$unopened_file" );

copy($fh[0],$fh[1]) || die "copy $unopened_file |gpg|mail failed: $!";

bitcoin.PL contains.
Code:
use Finance::Bitcoin;
my $wallet = Finance::Bitcoin::Wallet->new(
'http://bitcoinrpc:blahblahblah@127.0.0.1:8332/'
);
( $wallet, $wallet->api );


thank you for sharing. i extended your script with parameters and config-file.
will upload/share when finished. will try add ssl config for wallet-connection too.

greetings!


That's correct, this example is vastly site specific.  It doesn't handle password protected wallets it would also be nice if the command to pipe to(mail) was configurable.  ssh/curl/cat are good examples.
cheako911 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
March 06, 2015, 06:07:47 AM
 #4

After looking at a few of the backups, I've decided that bitcoind needs a keypoolrefill prior to making the backup.

The default value is 100, but I feel that the code could auto-scale up for large sites if it recorded the number of records that were dumped each time.
cheako
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
May 14, 2015, 06:17:49 AM
 #5

Does anyone know why bitcoind->dumpwallet now doesn't write to a fifo as it used too?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!