Advertisement
_IlyaVasilev_

Untitled

Oct 29th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/bash
  2. if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  3.     (echo "Back up files with the specified extension to the specified path to the specified folder: "
  4.     echo -e "\t./backup source_files files_extension source_archive"
  5.     echo -e "\tOnce buck up files"
  6.     echo "Keys:"
  7.     echo -e "\t-t or --time:\tSets period of backup in format:\n\tminute hour day month day_of_week\n"
  8.     echo -e "\t-c or --count:\tSets count of backup\n\tIf count of backup bigger than the specified number\n\tdeletes the old backups (count - 1) and creates another backup\n"
  9.     echo "Examples:"
  10.     echo -e "\t./backup -t 0 * * * * source_files files_extension source_archive\n\tBackups files at the begginning of every hour\n"
  11.     echo -e "\t./backup -c 5 source_files files_extension source_archive\n\tSaves no more than the 5 archives in source_archive\n"
  12.     echo -e "\t./backup -tc * * * * * 5 source_files files_extension source_archive\n\tBackups files every minutes and saves no more\n\tthan 5 the archives in source_files")
  13.     exit 0
  14. elif [ "$1" == "-t" ] || [ "$1" == "--time" ]; then
  15.     touch config.txt
  16.     echo $7 > config.txt
  17.     echo $8 >> config.txt
  18.     echo $9 >> config.txt
  19.     crontab -r
  20.     exit 0
  21. fi 
  22. readarray -a settings < config.txt
  23. cd ${settings[2]}
  24. tar -cf archive.tar ${settings[0]}/*.${settings[1]}
  25. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement