Post
Topic
Board Development & Technical Discussion
Merits 2 from 1 user
Topic OP
Backup bitcoind wallet for servers example.
by
cheako911
on 26/02/2015, 23:11:55 UTC
⭐ Merited by ABCbits (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 );