@@ -512,3 +512,118 @@ def test_tablespace_in_pgdata_pgpro_1376(self):
512
512
513
513
# Clean after yourself
514
514
self .del_test_dir (module_name ,fname )
515
+
516
+ # @unittest.skip("skip")
517
+ def test_tablespace_handling (self ):
518
+ """
519
+ make node, take full backup, check that restore with
520
+ tablespace mapping will end with error, take page backup,
521
+ check that restore with tablespace mapping will end with
522
+ success
523
+ """
524
+ fname = self .id ().split ('.' )[3 ]
525
+ node = self .make_simple_node (
526
+ base_dir = os .path .join (module_name ,fname ,'node' ),
527
+ set_replication = True ,
528
+ initdb_params = ['--data-checksums' ],
529
+ pg_options = {
530
+ 'wal_level' :'replica' ,
531
+ 'max_wal_senders' :'2' })
532
+
533
+ backup_dir = os .path .join (self .tmp_path ,module_name ,fname ,'backup' )
534
+
535
+ self .init_pb (backup_dir )
536
+ self .add_instance (backup_dir ,'node' ,node )
537
+ node .slow_start ()
538
+
539
+ self .backup_node (
540
+ backup_dir ,'node' ,node ,backup_type = "full" ,
541
+ options = ["-j" ,"4" ,"--stream" ])
542
+
543
+ tblspace1_old_path = self .get_tblspace_path (node ,'tblspace1_old' )
544
+ tblspace2_old_path = self .get_tblspace_path (node ,'tblspace2_old' )
545
+
546
+ self .create_tblspace_in_node (
547
+ node ,'some_lame_tablespace' )
548
+
549
+ self .create_tblspace_in_node (
550
+ node ,'tblspace1' ,
551
+ tblspc_path = tblspace1_old_path )
552
+
553
+ self .create_tblspace_in_node (
554
+ node ,'tblspace2' ,
555
+ tblspc_path = tblspace2_old_path )
556
+
557
+ node .safe_psql (
558
+ "postgres" ,
559
+ "create table t_heap_lame tablespace some_lame_tablespace "
560
+ "as select 1 as id, md5(i::text) as text, "
561
+ "md5(repeat(i::text,10))::tsvector as tsvector "
562
+ "from generate_series(0,1000) i" )
563
+
564
+ node .safe_psql (
565
+ "postgres" ,
566
+ "create table t_heap2 tablespace tblspace2 as select 1 as id, "
567
+ "md5(i::text) as text, "
568
+ "md5(repeat(i::text,10))::tsvector as tsvector "
569
+ "from generate_series(0,1000) i" )
570
+
571
+ tblspace1_new_path = self .get_tblspace_path (node ,'tblspace1_new' )
572
+ tblspace2_new_path = self .get_tblspace_path (node ,'tblspace2_new' )
573
+
574
+ node_restored = self .make_simple_node (
575
+ base_dir = os .path .join (module_name ,fname ,'node_restored' ))
576
+ node_restored .cleanup ()
577
+
578
+ try :
579
+ self .restore_node (
580
+ backup_dir ,'node' ,node_restored ,
581
+ options = [
582
+ "-j" ,"4" ,
583
+ "-T" ,"{0}={1}" .format (
584
+ tblspace1_old_path ,tblspace1_new_path ),
585
+ "-T" ,"{0}={1}" .format (
586
+ tblspace2_old_path ,tblspace2_new_path )])
587
+ # we should die here because exception is what we expect to happen
588
+ self .assertEqual (
589
+ 1 ,0 ,
590
+ "Expecting Error because tablespace mapping is incorrect"
591
+ "\n Output: {0}\n CMD: {1}" .format (
592
+ repr (self .output ),self .cmd ))
593
+ except ProbackupException as e :
594
+ self .assertTrue (
595
+ 'ERROR: --tablespace-mapping option' in e .message and
596
+ 'have an entry in tablespace_map file' in e .message ,
597
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
598
+ repr (e .message ),self .cmd ))
599
+
600
+ node .safe_psql (
601
+ "postgres" ,
602
+ "drop table t_heap_lame" )
603
+
604
+ node .safe_psql (
605
+ "postgres" ,
606
+ "drop tablespace some_lame_tablespace" )
607
+
608
+ self .backup_node (
609
+ backup_dir ,'node' ,node ,backup_type = "delta" ,
610
+ options = ["-j" ,"4" ,"--stream" ])
611
+
612
+ self .restore_node (
613
+ backup_dir ,'node' ,node_restored ,
614
+ options = [
615
+ "-j" ,"4" ,
616
+ "-T" ,"{0}={1}" .format (
617
+ tblspace1_old_path ,tblspace1_new_path ),
618
+ "-T" ,"{0}={1}" .format (
619
+ tblspace2_old_path ,tblspace2_new_path )])
620
+
621
+ if self .paranoia :
622
+ pgdata = self .pgdata_content (node .data_dir )
623
+
624
+ if self .paranoia :
625
+ pgdata_restored = self .pgdata_content (node_restored .data_dir )
626
+ self .compare_pgdata (pgdata ,pgdata_restored )
627
+
628
+ # Clean after yourself
629
+ self .del_test_dir (module_name ,fname )