| 1 | |||
| 2 | =head1 DOCUMENTATION | ||
| 3 | |||
| 4 | =head2 SYNOPSIS | ||
| 5 | |||
| 6 | PROGRAM NAME: BakupProject | ||
| 7 | AUTHOR: Juan Lorenzo | ||
| 8 | |||
| 9 | =head2 CHANGES and their DATES | ||
| 10 | |||
| 11 | DATE: July 2024 | ||
| 12 | Version 1.0 | ||
| 13 | |||
| 14 | |||
| 15 | =head2 DESCRIPTION | ||
| 16 | |||
| 17 | Backup (tar -czvf) a Project plus | ||
| 18 | its Project.config file | ||
| 19 | |||
| 20 | =head2 USE | ||
| 21 | |||
| 22 | perl BackupProject.pl | ||
| 23 | |||
| 24 | =head2 Steps | ||
| 25 | |||
| 26 | 1. Read the BackupProject.config file in the user's | ||
| 27 | Project directory. This Project directory does not have to | ||
| 28 | be the same one that is being tarred | ||
| 29 | |||
| 30 | 2. Read configuration file to determine the directory that is being | ||
| 31 | tarred | ||
| 32 | |||
| 33 | 3. Confirm that the directory is a project. Otherwise output a warning. | ||
| 34 | |||
| 35 | 4. tar -czvf | ||
| 36 | |||
| 37 | 5. Message that process is complete | ||
| 38 | |||
| 39 | |||
| 40 | =head2 NOTES | ||
| 41 | |||
| 42 | We are using Moose. | ||
| 43 | Moose already declares that you need debuggers turned on | ||
| 44 | so you don't need a line like the following: | ||
| 45 | use warnings; | ||
| 46 | |||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | use Moose; | ||
| 51 | our $VERSION = '0.1.0'; | ||
| 52 | |||
| 53 | use aliased 'App::SeismicUnixGui::misc::L_SU_local_user_constants'; | ||
| 54 | use aliased 'App::SeismicUnixGui::configs::big_streams::BackupProject_config'; | ||
| 55 | use aliased 'App::SeismicUnixGui::misc::control'; | ||
| 56 | use File::Copy; | ||
| 57 | use Cwd; | ||
| 58 | |||
| 59 | =head2 Instantiate classes: | ||
| 60 | |||
| 61 | Create a new versions of the packages | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | my $BackupProject_config = BackupProject_config->new(); | ||
| 66 | my $L_SU_local_user_constants = L_SU_local_user_constants->new(); | ||
| 67 | my $control = control->new(); | ||
| 68 | |||
| 69 | =head2 | ||
| 70 | |||
| 71 | Internal definitions | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | my $success_counter = 0; | ||
| 76 | my $CWD = getcwd(); | ||
| 77 | |||
| 78 | =head2 Get configuration information | ||
| 79 | |||
| 80 | Assume Project is at least soft-linked | ||
| 81 | from the home dirctory | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | my ( $CFG_h, $CFG_aref ) = $BackupProject_config->get_values(); | ||
| 86 | my $project_directory = $CFG_h->{BackupProject}{1}{directory_name}; | ||
| 87 | $control->set_infection( $project_directory ); | ||
| 88 | $project_directory = $control->get_ticksBgone(); | ||
| 89 | |||
| 90 | print("BackupProject.pl, project_directory = $project_directory \n"); | ||
| 91 | |||
| 92 | my $HOME = $L_SU_local_user_constants->get_home(); | ||
| 93 | my $tar_input = $HOME . '/'. $project_directory; | ||
| 94 | |||
| 95 | =head2 Verify project is a true SUG project | ||
| 96 | |||
| 97 | collect project names | ||
| 98 | compare backup project against project names | ||
| 99 | |||
| 100 | =cut | ||
| 101 | |||
| 102 | my @PROJECT_HOME_aref = $L_SU_local_user_constants->get_PROJECT_HOMES_aref(); | ||
| 103 | my @project_name_aref = $L_SU_local_user_constants->get_project_names(); | ||
| 104 | my $CONFIGURATION = $L_SU_local_user_constants->get_CONFIGURATION(); | ||
| 105 | |||
| 106 | my @project_pathNname = @{ $PROJECT_HOME_aref[0] }; | ||
| 107 | my @project_name = @{ $project_name_aref[0] }; | ||
| 108 | |||
| 109 | my $length = scalar @project_pathNname; | ||
| 110 | |||
| 111 | print("BackupProject.pl,project_pathNnames are=@project_pathNname\n"); | ||
| 112 | #print("BackupProject.pl,CONFIGURATION= $CONFIGURATION\n"); | ||
| 113 | #print("BackupProject.pl,project names=@project_name\n"); | ||
| 114 | #print("Backup_PROJECT_PROJECTProject.pl,There are $length existant projects in /.L_SU/configuration\n"); | ||
| 115 | |||
| 116 | =pod | ||
| 117 | |||
| 118 | check to see that the project directory | ||
| 119 | that is to be backed up exists. | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | $L_SU_local_user_constants->set_PROJECT_name($project_directory); | ||
| 124 | my $project_exists = $L_SU_local_user_constants->get_PROJECT_exists(); | ||
| 125 | print("BackupProject.pl,Does project $project_directory exist? ans=$project_exists\n"); | ||
| 126 | |||
| 127 | =pod | ||
| 128 | |||
| 129 | check to see that the project directory contains Project.config | ||
| 130 | If Project.config exists then | ||
| 131 | copy this file with the Project during the backup | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | if ( $project_exists ) { | ||
| 136 | |||
| 137 | my $Project_configuration_exists = $L_SU_local_user_constants->user_configuration_Project_config_exists(); | ||
| 138 | print("BackupProject.pl, Project_configuration_exists=$Project_configuration_exists \n"); | ||
| 139 | |||
| 140 | if ($Project_configuration_exists) { | ||
| 141 | |||
| 142 | print("Found a real SeismicUnixGui project!\n"); | ||
| 143 | my $from = $CONFIGURATION.'/'.$project_directory.'/'.'Project.config'; | ||
| 144 | my $to = $tar_input; | ||
| 145 | |||
| 146 | copy( $from, $to ); | ||
| 147 | |||
| 148 | print("BackupProject.pl, copying $from to $to \n"); | ||
| 149 | } | ||
| 150 | else { | ||
| 151 | print("BackupProject.pl,unsuccessful\n"); | ||
| 152 | print("Not a real SeismicUnixGui project!\n"); | ||
| 153 | } | ||
| 154 | |||
| 155 | } else { | ||
| 156 | print("BackupProject.pl, Project for backing up does not exist \n"); | ||
| 157 | } | ||
| 158 | |||
| 159 | =head2 Tarring a project | ||
| 160 | |||
| 161 | remove the local path | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | my $ORIGDIR = '.'; | ||
| 166 | my $tar_options = "-hczvf "; | ||
| 167 | my $project2tar = './'.$project_directory; | ||
| 168 | |||
| 169 | my $perl_instruction = ("cd $HOME; tar $tar_options $project_directory.tz $project2tar"); | ||
| 170 | |||
| 171 | print("$perl_instruction\n"); | ||
| 172 | print("Generic \"Project.tz\" file is assumed to live in user\'s home directory\n"); | ||
| 173 | print("Tarring will follow any symbolic links to their origin\n"); | ||
| 174 | |||
| 175 | system($perl_instruction); |