203
204
my $win = ($^O eq 'MSWin32' ? 1 : 0);
204
205
my $CP_CMD = ($win eq 1 ? "copy /Y" : "cp -p");
205
206
my $xtrabackup_binary_file = 'xtrabackup_binary';
207
my %rsync_files_hash;
206
209
######################################################################
207
210
# program execution begins here
208
211
######################################################################
365
368
wait_for_safe_slave();
368
if (!$option_incremental) {
371
if (!$option_incremental && !$option_no_lock) {
372
# make a prep copy before locking tables, if using rsync
369
375
# flush tables with read lock
370
mysql_lockall() if !$option_no_lock;
374
379
if ($option_slave_info) {
379
384
# backup .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files
385
# (or finalize the backup by syncing changes if using rsync)
382
388
# resume ibbackup and wait till it has finished
383
389
my $ibbackup_exit_code = resume_ibbackup();
1603
1609
'extra-lsndir=s' => \$option_extra_lsndir,
1604
1610
'remote-host=s' => \$option_remote_host,
1605
1611
'stream=s' => \$option_stream,
1612
'rsync' => \$option_rsync,
1606
1613
'tmpdir=s' => \$option_tmpdir,
1607
1614
'no-lock' => \$option_no_lock,
1608
1615
'ibbackup=s' => \$option_ibbackup_binary,
1805
1817
# backup directory.
1807
1819
sub backup_files {
1820
my $prep_mode = shift;
1808
1821
my $source_dir = get_option(\%config, 'mysqld', 'datadir');
1812
1825
my $wildcard = '*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}';
1826
my $rsync_file_list;
1828
my $rsync_tmpfile_pass1 = "$option_tmpdir/xtrabackup_rsyncfiles_pass1";
1829
my $rsync_tmpfile_pass2 = "$option_tmpdir/xtrabackup_rsyncfiles_pass2";
1831
# prep_mode will pre-copy the data, so that rsync is faster the 2nd time
1832
# saving time while all tables are locked.
1833
# currently only rsync mode is supported for prep.
1834
if ($prep_mode and !$option_rsync) {
1838
if ($option_rsync) {
1840
$rsync_file_list = $rsync_tmpfile_pass1;
1842
$rsync_file_list = $rsync_tmpfile_pass2;
1844
open(RSYNC, ">$rsync_file_list")
1845
|| Die "Can't open $rsync_file_list for writing: $!\n";
1814
1848
opendir(DIR, $source_dir)
1815
1849
|| Die "Can't open directory '$source_dir': $!\n";
1816
1850
$now = current_time();
1817
print STDERR "\n$now $prefix Starting to backup .frm, .MRG, .MYD, .MYI,\n";
1852
$operation = "a prep copy of";
1854
$operation = "to backup";
1856
print STDERR "\n$now $prefix Starting $operation .frm, .MRG, .MYD, .MYI,\n";
1818
1857
print STDERR "$prefix .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files in\n";
1819
1858
print STDERR "$prefix subdirectories of '$source_dir'\n";
1820
1859
# loop through all database directories
1865
1904
if ($print_each_file) {
1866
1905
print STDERR "$prefix Backing up file '$source_dir/$database/$file'\n";
1868
if (!$option_remote_host && !$option_stream) {
1908
if ($option_rsync) {
1909
print RSYNC "$database/$file\n";
1911
$rsync_files_hash{"$database/$file"} = 1;
1913
} elsif (!$option_remote_host && !$option_stream) {
1869
1914
$src_name = escape_path("$source_dir/$database/$file");
1870
1915
$dst_name = escape_path("$backup_dir/$database");
1871
1916
system("$CP_CMD \"$src_name\" \"$dst_name\"")
1949
if ($option_rsync) {
1952
# do the actual rsync now
1953
$now = current_time();
1954
my $rsync_cmd = "rsync -t \"$source_dir\" --files-from=\"$rsync_file_list\" \"$backup_dir\"";
1955
print STDERR "$now Starting rsync as: $rsync_cmd\n";
1957
# ignore errors in the prep mode, since we are running without lock,
1958
# so some files may have disappeared.
1959
if (system("$rsync_cmd") && !$prep_mode) {
1960
Die "rsync failed: $!\n";
1963
$now = current_time();
1964
print STDERR "$now rsync finished successfully.\n";
1966
# Remove from $backup_dir files that have been removed between first and
1967
# second passes. Cannot use "rsync --delete" because it does not work
1968
# with --files-from.
1970
open(RSYNC, "<$rsync_tmpfile_pass1")
1971
|| Die "Can't open $rsync_tmpfile_pass1 for reading: $!\n";
1975
if (!exists $rsync_files_hash{$_}) {
1976
print STDERR "Removing '$backup_dir/$_'\n";
1977
unlink "$backup_dir/$_";
1982
unlink "$rsync_tmpfile_pass1" || \
1983
Die "Failed to delete $rsync_tmpfile_pass1: $!";
1984
unlink "$rsync_tmpfile_pass2" || \
1985
Die "Failed to delete $rsync_tmpfile_pass2: $!";
1990
$operation = "a prep copy of";
1992
$operation = "backing up";
1904
1994
$now = current_time();
1905
print STDERR "$now $prefix Finished backing up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files\n\n";
1995
print STDERR "$now $prefix Finished $operation .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files\n\n";