Advertisement
Halvhjearne

redisbackup.sh

Jul 26th, 2015
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.11 KB | None | 0 0
  1. # Redis-Database backup shell script
  2.  
  3. # Copyright (C) 2015  Halvhjearne
  4.  
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9.  
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. # Contact : halvhjearne@gmail.com
  19.  
  20. # set path to where your redis.rdb file is located
  21. REDISDBDIR=/var/lib/redis
  22. # set path to where you want the db file to end up
  23. DBBACKUPDIR=/media/4y3rt6fd-4f5g-6543-4366-6fa2b6d58a28/armabackup
  24.  
  25. ##########################################################
  26. # Dont touch this part                                   #
  27. ##########################################################
  28.  
  29. DBDIR=$DBBACKUPDIR/$(date +'%A')
  30. DBFILE=dump_$(date +%Y_%d-%m_%H.%M-%S).rdb
  31. DBNAMEINDIR=$DBDIR/$DBFILE
  32.  
  33. if [ -d $DBDIR ];then
  34.     echo "Dir '$(date +'%A')' already exists"
  35. else
  36.     echo "Creating $DBDIR"
  37.     mkdir -p "$DBDIR"
  38. fi
  39.  
  40. echo "Backing up Database To $DBNAMEINDIR ..."
  41.  
  42. cp $REDISDBDIR/dump.rdb $DBNAMEINDIR
  43. chmod 775 $DBNAMEINDIR
  44.  
  45. ##########################################################
  46. # Change how long you want to save a database copy below #
  47. ##########################################################
  48.  
  49. #show old db's, uncomment to use:
  50.                             #-mmin = +minutes
  51. #find ${DBBACKUPDIR} -type f -mmin +240
  52.                             #-mtime = +days
  53. #find ${DBBACKUPDIR} -type f -mtime +3
  54. ################## IMPORTANT: ############################
  55. # delete db's older than 7days, change the 7 below       #
  56. # or comment out with a # infront of the line to disable #
  57. ##########################################################
  58. #find $DBBACKUPDIR -type f -mtime +7 -delete
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement