Last active
November 7, 2017 20:03
-
-
Save p3t3r67x0/6aa0ffc9f6035663992d8c4a8798a202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import os | |
import tarfile | |
import datetime | |
def get_time_string(): | |
d = datetime.datetime.now() | |
return d.strftime('%d_%m_%Y_%H_%M') | |
def make_tarfile(filename, src_dir, dst_dir): | |
with tarfile.open('{}/{}'.format(dst_dir, '{}.tar.gz'.format(filename)), 'w:gz') as tar: | |
tar.add(src_dir, arcname=filename) | |
def main(): | |
src_dir = '/home/<username>/' | |
dst_dir = '/opt/backup' | |
filename = 'backup_{}'.format(get_time_string()) | |
make_tarfile(filename, src_dir, dst_dir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment