chuggerguy

backupmozilla

Nov 14th, 2026
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2. # filename: backupmozilla (do not rename it backupfirefox or anything with firefox in the name... see the pgreg below)
  3.  
  4. if [ -z "$1" ]; then
  5.    frequency="hourly"
  6. else
  7.    frequency=$1
  8. fi
  9.  
  10. mozillalocation="$HOME/.mozilla"
  11. backuplocation="$HOME/backup/mozilla/$frequency"
  12. thisscript=`basename $0`
  13.  
  14. if [ ! -d "$backuplocation" ]; then
  15.      mkdir -p $backuplocation
  16. fi
  17.  
  18. if [ $(ps aux | grep "[${thisscript:0:1}]${thisscript:1} $frequency" | wc -l) -gt 3 ]; then
  19.      echo "$thisscript $frequency is already running, exiting."
  20.      exit
  21. fi
  22.  
  23. name=$(date '+%Y-%m-%d_at_%H.%M.%S'.mozilla.tar)
  24. if pgrep firefox >/dev/null 2>&1; then name=$name.running; fi
  25.  
  26. cd $mozillalocation
  27. tar -cf $backuplocation/$name *
  28.  
  29. cd $backuplocation
  30. numbackups=$(ls | wc -l)
  31.  
  32. if [ $numbackups -gt 5 ]; then
  33.      ls -t | awk 'NR>5' | xargs rm
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment