{"id":13613409,"url":"https://github.com/shockz-offsec/Automatic-Notion-Backup","last_synced_at":"2025-04-13T15:33:06.958Z","repository":{"id":44813181,"uuid":"442255119","full_name":"shockz-offsec/Automatic-Notion-Backup","owner":"shockz-offsec","description":"This script automates the backup process of Notion data into Markdown and CSV formats. Additionally, the script processes the data to remove any AWS identifiers that may be present in the Markdown files, folders, and internal references to other files in the backup","archived":false,"fork":false,"pushed_at":"2023-09-17T20:24:17.000Z","size":80,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T16:12:32.771Z","etag":null,"topics":["api","automatic","automation","backup","export","linux","markdown","notion","remove","selenium","web-scraping","windows"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shockz-offsec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-27T19:33:22.000Z","updated_at":"2025-02-22T17:32:23.000Z","dependencies_parsed_at":"2024-01-16T23:30:28.403Z","dependency_job_id":"2fc103dc-53ec-4376-9859-f874943704af","html_url":"https://github.com/shockz-offsec/Automatic-Notion-Backup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockz-offsec%2FAutomatic-Notion-Backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockz-offsec%2FAutomatic-Notion-Backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockz-offsec%2FAutomatic-Notion-Backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockz-offsec%2FAutomatic-Notion-Backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shockz-offsec","download_url":"https://codeload.github.com/shockz-offsec/Automatic-Notion-Backup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248736154,"owners_count":21153540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","automatic","automation","backup","export","linux","markdown","notion","remove","selenium","web-scraping","windows"],"created_at":"2024-08-01T20:00:46.161Z","updated_at":"2025-04-13T15:33:06.669Z","avatar_url":"https://github.com/shockz-offsec.png","language":"Python","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# Automatic-Notion-Backup\nThis script automates the backup process of Notion data into Markdown and CSV formats. Additionally, the script processes the data to remove any AWS identifiers that may be present in the Markdown files, folders, and internal references to other files in the backup.\n\nIt should be noted that the script always keeps two backups: the current one and the previous one.\n\n\u003e !! At no time is the information (credentials, tokens) used in the script recompiled.!!\n\n## Requirements \u0026 Installation\nTo use this tool, you need to have the Selenium module installed. You can install it by running the following command in your terminal:\n\n```bash\npip install selenium\npip install requests\n```\n\nAfter that, you can download the repository by running the following commands:\n\n```bash\ngit clone https://github.com/shockz-offsec/Automatic-Notion-Backup.git\ncd Automatic-Notion-Backup\n```\n\n### Compatibility\n\nThis script is compatible with both Windows and Linux operating systems and requires Python 3.\n\n## Configuration\n\nThe script's configuration is defined in the config.json file, which has the following structure:\n\n```json\n{\n    \"REMOVE_IDS\": true,\n    \"NOTION_SPACE_ID\":\"Your_space_id\",\n    \"DOWNLOAD_PATH\": \"C:\\\\Users\\\\YourUsername\\\\Downloads\",\n    \"TARGET_PATH\": \"C:\\\\path\\\\to\\\\your\\\\backup\\\\folder\",\n    \"DEBUG_PATH\": \"C:\\\\path\\\\to\\\\your\\\\logs\\\\folder\",\n    \"EMAIL\":\"your_notion_email\",\n    \"PASSWORD\":\"your_password\"\n}\n```\n\n* `REMOVE_IDS`: a boolean parameter that indicates whether the script should remove AWS identifiers from the downloaded files.\n* `NOTION_SPACE_ID`: The space id of your notion notes.\n* `DOWNLOAD_PATH`: the path where the downloaded files will be stored.\n* `TARGET_PATH`: the path where the processed backup files will be stored.\n* `DEBUG_PATH`: the path where the script logs will be saved.\n* `EMAIL`: the email address associated with the Notion account.\n* `PASSWORD`: the password associated with the Notion account.\n\n## UPDATE 2023\nNotion has recently added security measures by creating a Notion backup link through internal API calls that require authentication and authorization, using token_v2 and space_id. \n\nTherefore, we have implemented web scraping authentication on the Notion account to enable downloading the export. This approach combines web scraping authentication with export requests via the internal API. \n\nAlthough the acquisition of token_v2 has been automated, it is still necessary to obtain the space_id of the Notion notes to be exported manually\n\n## How it works\n\nThe script automates the web scraping authentication process in the background, eliminating the need for user intervention. Subsequently, the script obtains the token_v2 and requests an export using Notion's internal calls, generating an export URL. \n\nThe export is downloaded and processed according to the user's choice in the configuration file, which can remove AWS identifiers from markdown files, folders, and internal file references. Old backups are then deleted, leaving only the current and most recent backups. \n\nThe processed export is compressed into a zip file with the format `notion_export-dd-mm-yyyy.zip`. \n\nAdditionally, the script generates a log file of all the actions performed during the process, using the `debug-dd-mm-yyyy.log` format.\n\nThe script uses the Firefox webdriver (geckodriver), which is automatically installed during the setup process.\n\n\n## Getting NOTION_TOKEN and SPACE_ID for using Notion API\n\n- Open your Notion in the browser\n- Right-click anywhere on the page and select \"Inspect Element\".\n  - 1º click on the \"Network\" tab, refresh the page (you can press F5).\n  - 2º Search for \"getPublicSpaceData\" and select one occurrence.\n  - 3º Your space ID is the first value associated with the first \"id\" field in the \"response\" tab.\n  - 4º Copy and paste that ID into the *config.json* file under the \"NOTION_SPACE_ID\" field.\n  \n![STEPS](https://user-images.githubusercontent.com/67438760/230782980-9794d5d9-1045-4f2a-923b-396b0725f255.png)\n\n## Usage\n\n```bash\npython3 notion_backup.py\"\n```\n\n## Automating backups\n\nIn Windows, you can automate the script by creating a scheduled task with the Windows Task Scheduler. This can be done by creating a `.bat` file with the following contents:\n\n```batch\n@echo off\nC:\\Python3\\python.exe \"C:\\path\\to\\notion_backup.py\"\n```\nThis will allow the script to run automatically at specified intervals without requiring manual intervention.\n\nIn Linux you can use Cron for example.\n\n## Complete web-scraping version removing the need for tokens and private Notion APIs\n\nThe backup process is entirely carried out in the background using web scraping, without requiring any user input.\n\n[Link to the Github repository](https://github.com/shockz-offsec/Scraping-Notion-Backup)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockz-offsec%2FAutomatic-Notion-Backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshockz-offsec%2FAutomatic-Notion-Backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockz-offsec%2FAutomatic-Notion-Backup/lists"}