Join/Login

Business Software

Open Source Software

For Vendors

Blog

About

More

Articles

Create

SourceForge Podcast

Site Documentation

Subscribe to our Newsletter

Support Request

For Vendors Help Create Join Login

Business Software

Open Source Software

SourceForge Podcast

Resources

Articles

Case Studies

Blog

Menu

Help

Create

Join

Login

Home

Browse

Iris

Calliope

Iris Calliope

2-photon scanning software

Brought to you by: heinmatt, kellgeor

Summary

Reviews

Support

Wiki

Tickets ▾

Bugs

Tasks

Feature Requests

SVN ▾

Iris Main

Auxiliary Code

Calliope

Discussion

Menu ▾ ▴

Browse Commits

Browse Files

[r1193]: / 01_DataManagement / primary_backup.m  Maximize  Restore  History

Download this file

228 lines (194 with data), 7.2 kB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

function results=primary_backup(proj, exp_ids, varargin)

% primary data backup function

% input:

% proj - the project you want to back up data for

% exp_ids - experimental IDs

% optional inputs

% 'md5',option - check MD5 sum for file integrity (default: 1)

% 'email','emailadress' - notification per email with summary

%

% e.g. primary_backup('OMM',10000:10005);

% primary_backup('OMM',[10000, 10020],'email','marcus.leinweber');

%

% for a new setup, add file locations in primary_backup_define.m

% ML

if ~isstr(proj)

disp('Input argument error!');

disp('usage: primary_backup(projID,ExpIDs);');

return

end

persistent strCR % for textprogressbar

textprogressbar('inittextprogressbar')

md5check = 0;

email = [];

messages = {'Backup Script'};

if ~isempty(varargin)

numIndex = find(cellfun('isclass', varargin(1:end-1), 'char'));

for ind = 1:length(numIndex)

switch lower(varargin{numIndex(ind)})

case 'md5'

md5check = varargin{numIndex(ind) + 1};

case 'email'

email = varargin{numIndex(ind) + 1};

end

end

end

warnings = {};

disp('clearing ExpLog in ''base'' workspace');

evalin('base','clear ExpLog');

ExpLog=getExpLog;

assignin('base','ExpLog', ExpLog);

% proj=ExpLog.project{find(cell2mat(ExpLog.expid)==exp_ids(1),1,'first')};

[isok, source_dir, backup_loc] = primary_backup_define(proj);

if ~isok

return

end

no_backup_loc = size(backup_loc,2);

% path md5.exe later on

path_mfile = fileparts(which(mfilename));

if nargin<2

exp_id_inds = [1:length(ExpLog.expid)]';

else

exp_id_inds = find(ismember(cell2mat(ExpLog.expid),exp_ids));

end

% ignore ExpIDs from different projects

projs = ExpLog.project(exp_id_inds);

exp_id_inds = exp_id_inds(strcmp(proj,projs));

StackIDs = cell2mat(ExpLog.stackid(exp_id_inds));

fprintf(['Following stacks were found in DB: ' num2str(cell2mat(ExpLog.stackid(exp_id_inds))') '\n'])

animal_id = ExpLog.animalid(exp_id_inds);

user_id = ExpLog.pi(exp_id_inds);

% built file locations

sources_files = {};

backup_files = {};

total_size = 0;

fprintf('\n');

textprogressbar('Put all file locations together: ');

for ind = 1:length(StackIDs)

textprogressbar(ind/length(StackIDs)*100);

for jnd = 1:size(source_dir,2)

d = dir(fullfile(source_dir{jnd},[ '*' num2str(StackIDs(ind)) '*']));

if size(d,1) > 0

total_size = total_size + sum([d.bytes]);

for knd = 1:size(d,1)

sources_files{end+1} = fullfile(source_dir{jnd},d(knd).name);

for lnd = 1:no_backup_loc

backup_files{end+1} = fullfile(backup_loc{lnd},user_id{ind},animal_id{ind},d(knd).name);

end

end

end

end

end

no_source_files = size(sources_files,2);

no_backup_files = size(backup_files,2);

textprogressbar(' done');

if no_source_files == 0

disp('ERROR !!! - could not find any data to copy. did you export your labnotes?');

disp('Or you are not using ExpIDs...');

return;

end

textprogressbar('Check space on backup locations: ');

for ind = 1:no_backup_loc

if disk_free(backup_loc{ind}) < total_size

textprogressbar(' error');

error(['Not enough disk space on backup location: ' backup_loc{ind}]);

else

messages{end+1} = ['Backup location ' num2str(ind) ': ' backup_loc{ind}];

end

textprogressbar(ind/no_backup_loc*100);

end

textprogressbar(' done');

backup_files = regexprep(backup_files,'\s+','');

sources_files = regexprep(sources_files,'\s+','');

textprogressbar('Copying files: ');

for ind = 1:no_backup_files

% check whether directory exist

if ~isdir(fileparts(backup_files{ind}))

mkdir(fileparts(backup_files{ind}));

end

textprogressbar(ind/no_backup_files*100);

if ~exist(backup_files{ind},'file')

% disp(['-> ' sources_files{ceil(ind/no_backup_loc)} ' >> ' backup_files{ind}]);

[success(ind),mtext] = copyfile(sources_files{ceil(ind/no_backup_loc)},backup_files{ind});

else

warnings{end+1} = ([backup_files{ind} ' - FILE ALREADY EXISTS - skipping.']);

success(ind) = 1;

end

if ~success(ind)

warnings{end+1} = strtrim([backup_files{ind} ' - Some problem with copying: ' mtext]);

success(ind) = 0;

end

end

textprogressbar(' done');

mdsum_s = {};

mdsum_c = zeros(1,no_backup_files);

mdsum_b = {};

if md5check

textprogressbar('Calculating MD5 for source files: ');

for ind = 1:no_source_files

textprogressbar(ind/no_source_files*100);

[s,w] = dos([path_mfile '\md5.exe ' sources_files{ind}]);

if s == 0

w = regexp(w, ' ', 'split');

mdsum_s{ind} = w{1};

else

mdsum_s{ind} = {-1};

end

end

textprogressbar(' done');

textprogressbar('Calculating MD5 for backup files: ');

for ind = 1:no_backup_files

textprogressbar(ind/no_backup_files*100);

[s,w] = dos([path_mfile '\md5.exe ' backup_files{ind}]);

if s == 0

w = regexp(w, ' ', 'split');

mdsum_b{ind} = w{1};

else

mdsum_b{ind} = {0};

end

end

textprogressbar(' done');

textprogressbar('Comparing MD5 sums: ');

for ind = 1:no_backup_files

mdsum_c(ceil(ind/no_backup_loc)) = mdsum_c(ceil(ind/no_backup_loc)) + ...

strcmp(mdsum_b{ind},mdsum_s{ceil(ind/no_backup_loc)});

textprogressbar(ind/no_backup_files*100);

end

textprogressbar(' done');

end

% plot summary

messages{end+1} = ['Animal' char(9) char(9) '|StackID |' char(9) 'No.files |'...

char(9) 'No.files copied |' char(9) 'MD5 OK'];

for ind = 1:length(StackIDs)

inds = cellfun(@(x)(~isempty(x)),regexp(sources_files,num2str(StackIDs(ind))));

inds2 = repmat(inds,[no_backup_loc 1]);

inds2 = logical(inds2(:)');

messages{end+1} = [animal_id{ind} ' | ' num2str(StackIDs(ind)) char(9) ' |' ...

char(9) char(9) num2str(sum(inds)) ' |' char(9) char(9) char(9) char(9) ...

num2str(sum(success(inds2))) char(9) ' |' char(9) char(9) ...

num2str(sum(mdsum_c(inds))) ];

end

if sum(success) == no_backup_loc

messages{end+1} = [num2str(total_size/1024^3) 'GB of data was transferred to ' num2str(no_backup_loc) ' locations.'];

end

if ~isempty(warnings)

messages{end+1} = 'Warnings/ Errors: ';

messages = [messages warnings];

end

for ind = 1:size(messages,2)

fprintf([regexprep(messages{ind},'\\','\\\\') '\n'])

end

% send email notification

if ~isempty(email)

setSMTPprefGmail;

if isempty(regexp(email,'\@','once'))

email = [email '@fmi.ch'];

end

sendmail(email,'backup script',messages);

end

results.sources_files = sources_files;

results.backup_files = backup_files;

results.copiedsuccess = success;

results.mdsum_s = mdsum_s;

results.mdsum_b = mdsum_b;

results.warnings = warnings;

SourceForge

Create a Project

Open Source Software

Business Software

Top Downloaded Projects

Company

About

Team

SourceForge Headquarters
225 Broadway Suite 1600
San Diego, CA 92101
+1 (858) 422-6466

Resources

Support

Site Documentation

Site Status

SourceForge Reviews

© 2025 Slashdot Media. All Rights Reserved.

Terms Privacy Opt Out Advertise

×
Want the latest updates on software, tech news, and AI?

Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.

Submit