BASH   54

backup sh

Guest on 15th May 2022 04:46:40 PM

  1. #!/bin/bash
  2. ###########
  3.  
  4. dir=$1           # dir to backup
  5. path=/backup     # main backup dir
  6.  
  7. date=`date +%Y%m%d`
  8. unixtime=`date +%s`
  9. path=$path/$date
  10. path=`echo $path | sed 's/^\///g'`
  11. mkdir -p /$path
  12.  
  13. # delete old
  14. day=31
  15. unixtime=`date +%s`
  16. old=$(($unixtime-(60*60*24*$day)))
  17. old=`date -d @$old "+%Y%m"`
  18. touch /$path/$old.tmp
  19. rm -r  /$path/$old*
  20. # delete old end
  21.  
  22. cd /
  23. if [ -z "$dir" ];then
  24. echo
  25. echo Usage: ./`basename $0` [dir]
  26. echo
  27. exit
  28. fi
  29.  
  30. if [ ! -z "$dir" ];then
  31. from=`echo $dir | sed 's/^\///g'`
  32. to=`echo $from | sed 's/\//-/g'`
  33. /bin/tar zcf $path/$to-$unixtime.tar.gz $from
  34. exit
  35. fi

Raw Paste


Login or Register to edit or fork this paste. It's free.