Created
April 25, 2020 15:05
-
-
Save mehdichaouch/7a0e5d07611119800280047c4142d0e7 to your computer and use it in GitHub Desktop.
Automatically backup Google Chrome important files ('Current Session','Current Tabs','Last Session','Last Tabs','Bookmarks','Preferences') to Google Drive by default. This can be added in crontab for more efficiency.
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
#!/bin/sh | |
### | |
# @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | |
# @author Mehdi Chaouch <[email protected]> <@advocodo> | |
# @copyright Copyright (c) 2020 ADVOCODO (https://www.advocodo.com) | |
### | |
#set -v | |
#set -x | |
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
PROGNAME=$(basename $0) | |
error_exit() { | |
echo "⚠️ ${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 | |
exit 1 | |
} | |
usage() { | |
usage="Automatically backup Google Chrome important files ('Current Session','Current Tabs','Last Session','Last Tabs','Bookmarks','Preferences') to Google Drive by default | |
usage: | |
$PROGNAME [-h] -p profile -t target_folder | |
General Options: | |
-h, --help Show help. | |
-p Google Chrome profile name (default: $PROFILE). | |
-t target folder to backup files (default: $TARGET). | |
Exemple: | |
sh $PROGNAME -p Default -t $HOME/GDrive/__Google_Chrome_backup_files | |
this can be added in crontab for more efficiency: | |
* * * * * sh $CURRENT_DIR/$PROGNAME -p Default -t $HOME/GDrive/__Google_Chrome_backup_files 1>&2" | |
echo "$usage" >&2 | |
exit 1 | |
} | |
while getopts ":h:p:t:" OPTION; do | |
case "$OPTION" in | |
h) usage | |
;; | |
p) PROFILE=$OPTARG | |
;; | |
t) TARGET=$OPTARG | |
;; | |
:) printf "missing argument for -%s\n" "$OPTARG" >&2 | |
usage | |
;; | |
\?) printf "illegal option: -%s\n" "$OPTARG" >&2 | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# Make sure user entered all required parameters | |
[ -z "${PROFILE}" ] || [ -z "${TARGET}" ] && usage | |
mkdir -p $TARGET | |
FILES=("Current Session" "Current Tabs" "Last Session" "Last Tabs" "Bookmarks" "Preferences") | |
for FILENAME in "${FILES[@]}"; do | |
SRC="$HOME/Library/Application Support/Google/Chrome/$PROFILE/$FILENAME" | |
[ ! -f "$SRC" ] && continue | |
cp -a "$SRC" "$TARGET" && echo "🍺 Backuped « $TARGET/$FILENAME » successfully" || error_exit "Error backuping « $TARGET/$FILENAME »" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment