1 # BookStack Data Exporter
3 This Ruby script allows you to export data from a BookStack instance into a CSV file. The exported data includes information about pages, books, and shelves, along with their respective URLs and modification dates.
7 Before running the script, make sure you have the following:
9 - Ruby installed on your system
10 - Access to a BookStack instance with API enabled
11 - BookStack API token ID and token secret
15 1. Clone this repository or download the script file.
16 2. Install the required dependencies by running the following command:
22 3. Create a `.env` file in the same directory as the script and provide the following environment variables:
25 BS_URL=<your_bookstack_url>
26 BS_TOKEN_ID=<your_api_token_id>
27 BS_TOKEN_SECRET=<your_api_token_secret>
30 Replace `<your_bookstack_url>`, `<your_api_token_id>`, and `<your_api_token_secret>` with your actual BookStack URL, API token ID, and API token secret, respectively.
34 To run the script and export the data, execute the following command:
37 ruby export_bookstack_data.rb
40 The script will retrieve data from your BookStack instance and generate a CSV file named `bookstack_data.csv` in the same directory.
44 The generated CSV file will have the following columns:
46 - Type: Indicates whether the row represents a page or a book.
47 - ID: The unique identifier of the page or book.
48 - Name: The name of the page or book.
49 - URL: The URL of the page or book, formatted as an Excel hyperlink.
50 - Book ID: The ID of the book to which the page belongs (applicable only for pages).
51 - Book Name: The name of the book to which the page belongs (applicable only for pages).
52 - Book URL: The URL of the book, formatted as an Excel hyperlink (applicable only for pages).
53 - Shelf Name: The name of the shelf to which the book belongs.
54 - Date Modified: The last modification date of the page or book.
56 The URLs in the 'URL' and 'Book URL' columns are wrapped in the `=HYPERLINK()` function, allowing you to easily access the respective pages and books directly from the CSV file when opened in Excel.
57 HYPERLINK() - is an Excel shortcut to make URL clickable, feel free to remove, if you don't use Excel.
61 Logging to STDOUT, but can be adjusted to a file.
65 Here's an example of how the generated CSV file might look.
68 Type,ID,Name,URL,Book ID,Book Name,Book URL,Shelf Name,Date Modified
69 Page,1,Introduction,=HYPERLINK("https://example.com/books/1/page/1"),1,User Guide,=HYPERLINK("https://example.com/books/1"),Getting Started,2023-05-01T10:00:00.000000Z
70 Page,2,Installation,=HYPERLINK("https://example.com/books/1/page/2"),1,User Guide,=HYPERLINK("https://example.com/books/1"),Getting Started,2023-05-02T11:30:00.000000Z
71 Book,1,User Guide,=HYPERLINK("https://example.com/books/1"),,,,Getting Started,2023-05-01T09:00:00.000000Z
76 This script is released under the [MIT License](LICENSE).
78 Feel free to customize and adapt the script to suit your specific requirements.