Skip to content

Commit

Permalink
Make partial backups optional (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdstaaij committed Jan 2, 2016
1 parent ccd03d0 commit 77ea043
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@
# because of a large media file
media_timeout: 0


## Advanced behavior settings ##

# Setting this to true will record backup progress in a json file in the
# output directory, and use this to backup incrementally (only new messages)
track_progress: false

# Replacement string for the characters in dialog names which are potentially
# problematic in filenames
# You can set this to '' if the dialog names are unique enough
Expand Down
37 changes: 21 additions & 16 deletions telegram-history-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,22 @@ def format_dialog_list(dialogs)

$progress = {}
$progress_snapshot = {}
progress_file = File.join(get_backup_dir, 'progress.json')
progress_json = File.exists?(progress_file) ? File.read(progress_file) : '{}'
progress_hash = JSON.parse(progress_json)
if progress_hash['dumper'] && progress_hash['dumper'] != $config['dumper']
raise 'Dumper conflict: configured for "%s" but progress file reads "%s". '\
if $config['track_progress']
progress_file = File.join(get_backup_dir, 'progress.json')
progress_json = File.exists?(progress_file) ? File.read(progress_file) : '{}'
progress_hash = JSON.parse(progress_json)
if progress_hash['dumper'] && progress_hash['dumper'] != $config['dumper']
raise 'Dumper conflict: configured for "%s" but progress file reads "%s". '\
'Either use the same dumper or delete the output directory.'\
% [progress_hash['dumper'], $config['dumper']]
end
(progress_hash['dialogs'] || {}).each do |k,v|
$progress[k] = DumpProgress.from_hash(v)
$progress_snapshot[k] = DumpProgress.from_hash(v)
end
(progress_hash['dialogs'] || {}).each do |k,v|
$progress[k] = DumpProgress.from_hash(v)
$progress_snapshot[k] = DumpProgress.from_hash(v)
end
end


$log.info('Loading dumper module \'%s\'' % $config['dumper'])
require_relative 'dumpers/%s/dumper.rb' % $config['dumper']
$dumper = Dumper.new
Expand Down Expand Up @@ -237,13 +240,15 @@ def format_dialog_list(dialogs)
end
end

$log.info('Saving progress file')
progress_hash = {
:dumper => $config['dumper'],
:dialogs => $progress
}
progress_json = JSON.pretty_generate(progress_hash) + "\n"
File.write(progress_file, progress_json)
if $config['track_progress']
$log.info('Saving progress file')
progress_hash = {
:dumper => $config['dumper'],
:dialogs => $progress
}
progress_json = JSON.pretty_generate(progress_hash) + "\n"
File.write(progress_file, progress_json)
end

$dumper.end_backup
if cli_opts.kill_tg
Expand Down

0 comments on commit 77ea043

Please sign in to comment.