Skip to content

Instantly share code, notes, and snippets.

@shuckster
Last active February 26, 2024 07:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuckster/a91724adf5db1897ef07a69165b40e44 to your computer and use it in GitHub Desktop.
Save shuckster/a91724adf5db1897ef07a69165b40e44 to your computer and use it in GitHub Desktop.
Backup Google Chrome bookmarks across all Chrome Profiles
#!/bin/sh
#
# Backup Google Chrome bookmarks across all Chrome Profiles.
# Tested on macOS, but should work on other *nix systems.
#
# Download and install:
#
# curl -s https://gist.githubusercontent.com/shuckster/a91724adf5db1897ef07a69165b40e44/raw/backup-bookmarks.sh -o ./backup-bookmarks.sh
# chmod +x ./backup-bookmarks.sh
# ./backup-bookmarks.sh --install
#
# Written by Conan: https://gist.github.com/shuckster/a91724adf5db1897ef07a69165b40e44
#
cd "${0%/*}" || exit
# (^- change the working-directory to where this script is)
machine_name=$(uname -n | sed 's/[^a-zA-Z0-9]/_/g')
time_stamp=$(date "+%Y-%m-%d__%H.%M")
backup_folder="/Users/$USER/Dropbox/Bookmarks/${machine_name}/${time_stamp}"
crontab_install()
{
# https://unix.stackexchange.com/a/76604
this_script=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
echo "Suggested crontab line:"
echo ""
echo " 0 12 * * * $this_script"
echo ""
echo "Press [Enter] to open 'crontab -e' where you can paste the above line."
read -r
crontab -e
crontab -l
}
perform_backup()
{
mkdir -p "$backup_folder" || failure "Could not create backup folder: $backup_folder"
count=0
for bookmark in /Users/$USER/Library/Application\ Support/Google/Chrome/**/Bookmarks
do
count=$((count+1))
dest="$backup_folder/Bookmarks_Profile_${count}.json"
echo "Backing up Chrome Bookmark file..."
echo " From: '$bookmark'"
echo " To: '$dest'"
cp "$bookmark" "$dest" || failure "Failed to backup above bookmarks file"
done
}
failure()
{
echo "Error: $1"
exit 1
}
if [ "$1" = '--install' ]
then
crontab_install
exit 0
fi
perform_backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment