Yarn does not offer a backup/restore feature, so I created this script.
Backup the global package.json file
$ cp $(yarn global dir)/package.json /path/to/your/backup/folder
# use without install
$ npx yarn-global-restore </path/to/package.json> [--keep-versions]
# install globally
$ yarn global add yarn-global-restore
--keep-versions
(optional): install with saved versions, otherwise install newest versions