Coder Social home page Coder Social logo

mattab / trello-backup Goto Github PK

View Code? Open in Web Editor NEW
354.0 24.0 73.0 57 KB

Trello-Backup is a simple script that Backups all your Trello.com boards and cards, one JSON file per board, for total peace of mind. This is a simple php script which uses the Trello.com API to securely fetch all your boards and store them on your computer as raw JSON files.

License: GNU General Public License v3.0

PHP 100.00%

trello-backup's Introduction

Trello-Backup

Trello-Backup is a simple script that Backups all your Trello.com boards and cards, one JSON file per board, for total peace of mind. This is a simple php script which uses the Trello.com API to securely fetch all your boards and store them on your computer.

Requirements

This is a simple php script which requires PHP installed on your system: sudo apt-get install php7

Usage

  • Download the code in a 'trello-backup' directory with: git clone https://github.com/mattab/trello-backup.git trello-backup
  • Duplicate the config.example.php file to config.php and fill in your details (as follows)
  • With your browser go to: https://trello.com/1/appKey/generate - It will give you your public 'Key' for Trello API.
  • Edit the file trello-backup/config.php and set $key to your 'Key'.
  • Then Run the script: php trello-backup/trello-backup.php It will output a URL that you can visit with your browser to get the Application Token. Visit this URL. Then click 'Allow' and copy the token string.
  • Edit config.php and paste this token in $application_token.
  • You are ready! Run this script will download your Trello boards: php trello-backup/trello-backup.php It will create a file named trello-org-[OrganizationNameHere]-board-[NameHere].json for each of your board. Also recommended: setup a crontab to automatically backup every day or every week.

Enjoy!

How to backup several accounts

If you want to backup multiple Trello accounts, you can make multiple copies of example-config.php with different file names. Run trello-backup.php once for each account, specifying the path to the config file as an argument. For example, php trello-backup.php account1.php.

Why Trello-Backup?

Trello.com is a really wonderful free tool, but it has one technical issue 'by design': it is not Free Software that we can self host ourselves.

Also the fine weather can turn to rain pretty quickly: We cannot trust the clouds 100%.

Plus I'm pretty sure others would like to backup their Trello data!

Who is Trello-Backup for?

For anyone using Trello.com who wants to ! but especially:

  • if you store a lot of great ideas and tasks,
  • if you carefully plan long checklists full of unique requirements and thoughts,
  • if you have not only one board but several boards all of them containing important data,
  • if you are thinking of going on a No-Internet holiday for a few weeks and wish to access your boards while offline...

What does this do in terms of clouds?

This little script keeps your data out of the clouds!

What is Trello?

Trello is a free web-based project management application made by Fog Creek Software. Trello uses a paradigm for managing projects known as kanban, a method that had originally been popularized by Toyota in the 1980s for supply chain management. Projects are represented by boards, which contain lists (corresponding to task lists). Lists contain cards (corresponding to tasks). Cards are supposed to progress from one list to the next (via drag-and-drop), for instance mirroring the flow of a feature from idea to implementation. Users can be assigned to cards. Users and boards can be grouped into organizations.

Source: Trello on Wikipedia

Revoking your Trello API Token after use

After backuping your Trello boards, you can easily revoke your token if you wish. Go to trello.com/my/account, scroll down to "Applications" and click "Revoke". See this Trello help page for more info.

Common Issues

Fatal error: Maximum execution time of x seconds exceed in (Directory here). The simple fix here is to edit your php.ini file and set the max_execution_time attribute to 0 to allow your script to run as long as you need it to.

Credits

This is my first Github project! ~ Matthieu Aubry

Kuddos to Zander on Github for his help, when I was trying to use his trello-archiver.

This script officially started from this Gist!

The README Is longer than the script - I'm also practising Markdown.

trello-backup's People

Contributors

antiharmonic avatar arnisoph avatar chrisspiegl avatar codebrauer avatar ehj-52n avatar friendlydan avatar lazartravica avatar martijnengler avatar mattab avatar mkj avatar nilsree avatar popod avatar pronobis avatar r-omk avatar ransford avatar samwilson avatar sciurus avatar tirithen avatar visch avatar vrillusions avatar zetten avatar zph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trello-backup's Issues

Get warning because Timezone is not set

I get a warning because the timezone is not explicitly set by the script. I just add date_default_timezone_set('UTC'); in the function getPathToStoreBackups below. Not a huge deal, but thought I would share.

function getPathToStoreBackups($path, $board, $filename_append_datetime)
{
    date_default_timezone_set('UTC');
    return "$path/trello"
    . (($board->closed) ? '-CLOSED' : '')
    . (!empty($board->orgName) ? '-org-' . sanitize_file_name($board->orgName) : '')
    . '-board-' . sanitize_file_name($board->name)
    . (($filename_append_datetime) ? '-' . date($filename_append_datetime, time()) : '');
}

attachments get stored under original Trello board

I have many Trello boards and sometimes I copy cards with attachments from one board to another.

If I backup Trello boards the attachments get stored under the original board they originally got attached to and not the board they got copied to.

Not sure yet if this is a script issue or Trello just storing the attachments once under the original board and just linking to the new one.

Backupping boards with more than 20,000 cards

Trello export has a 20,000 card limit [1] so boards with more than 20,000 cards created (including archived cards) won't be backupped succesfully by this trello-backup script [2].

Workaround is to create a new board and move only the active cards there and start backupping the new board but maybe it would be possible to add a support to this script to do the json export in batches to enable support for more cards?

[1] https://trello.com/1/resource/limits
[2] "Failed to open stream: HTTP request failed! HTTP/1.1 449 Unknown"

Attachment's with the same name

My organization have multiple board's where multiple screenshot's is pasted into card's.
When doing so the image-attachement will be named "image.png".

The attachment backup will save files with it's original file name, and will therefore overwrite "image.png" multiple times.

I would suggest to create a filename prefix based on the card's name or id, or create a sub folder based on the card's name or id.

PHP Warning: file_get_contents(...): failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required

When executing trello-backup I started repeatedly getting the following error message:

PHP Warning: file_get_contents(...): failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required

I'm running:

PHP 5.6.40-0+deb8u12 (cli) (built: Jun 28 2020 09:37:30)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Any idea what is the reason for that?

Thanks.

the backup attachments option is buggy

My config.php:

$key = 'YYYY;
$application_token = 'XXXX';
$backup_closed_boards = false;
$backup_all_organization_boards = true;
$backup_attachments = true;
$path = dirname(__FILE__).'/boards';
$proxy= '';
$ignore_boards = array('Welcome Board');
$filename_append_datetime = true;

When I run the script, I get these errors:

$ php5 trello-backup.php 
262 boards to backup... 
recording board 'Todo Thibauld' (within organization 'Thibauld') in filename /home/thibauld/democratech/backup/trello-backup/boards/trello-org-telegraph-board-Todo-Telegraph-1.json ...
recording board 'Jean-Pierre PAIRAULT' (within organization 'jean-pierre PAIRAULT') in filename /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1.json ...
    1 attachments will now be downloaded and backed up...
    1) aux_rames_citoyens_001.jpg in /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg
recording board 'auxramescitoyens' (within organization 'jean-pierre PAIRAULT') in filename /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-jean-pierre-PAIRAULT-board-auxramescitoyens-1.json ...
PHP Warning:  file_put_contents(/home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-jean-pierre-PAIRAULT-board-auxramescitoyens-1.json): failed to open stream: No such file or directory in /home/thibauld/democratech/backup/trello-backup/trello-backup.php on line 105
recording board 'qui suis-je' (within organization 'jean-pierre PAIRAULT') in filename /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-jean-pierre-PAIRAULT-board-qui-suis-je-1.json ...
PHP Warning:  file_put_contents(/home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-jean-pierre-PAIRAULT-board-qui-suis-je-1.json): failed to open stream: No such file or directory in /home/thibauld/democratech/backup/trello-backup/trello-backup.php on line 105
recording board 'Articles & Discours' (within organization 'democratech') in filename /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-democratech-board-Articles-Discours-1.json ...
PHP Warning:  file_put_contents(/home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-democratech-board-Articles-Discours-1.json): failed to open stream: No such file or directory in /home/thibauld/democratech/backup/trello-backup/trello-backup.php on line 105
    56 attachments will now be downloaded and backed up...
PHP Warning:  mkdir(): Not a directory in /home/thibauld/democratech/backup/trello-backup/trello-backup.php on line 121
PHP Warning:  file_put_contents(/home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-democratech-board-Articles-Discours-1/httpwww.laviedesidees.frLes-vertus-du-plus-grand-nombre.html): failed to open stream: No such file or directory in /home/thibauld/democratech/backup/trello-backup/trello-backup.php on line 126
    1) http://www.laviedesidees.fr/Les-vertus-du-plus-grand-nombre.html in /home/thibauld/democratech/backup/trello-backup/boards/trello-org-jean-pierre-PAIRAULT-board-Jean-Pierre-PAIRAULT-1/aux_rames_citoyens_001.jpg/trello-org-democratech-board-Articles-Discours-1/httpwww.laviedesidees.frLes-vertus-du-plus-grand-nombre.html
^C

Running the script with $backup_attachments=false; produces no error and works fine.

The script fails if I have no organisations

Trello allows you to have boards for your own use only. When used like this (with no organisations) the script fails "Failed to download organisations".

I had to create an empty organisation in Trello for the script to work. Perhaps this can be fixed?

Don't break the process when an organization is empty (no boards)

I had a few empty organization (with no boards).
In you script, you die when it occur.
Supposing it's always caused by a token error.

It could but it could also be my case, an empty organization.

So I've changes the line 49 die with print_r
49 print_r("Error requesting the organization $organization_name boards - maybe check your tokens are correct.\n");

bug & feature requests for attachments download

  1. I noticed that it would download the destination instead of saving the hyperlink in the attachments for which the hyperlink was attached to cards.
  2. Allowing attachment downloads to include/exclude for the organizations/boards would be good.
  3. Boards backgrounds backup?

include a config.example.php instead of the ocnfig.php

The reason for this would be that since now the config.php is in the .gitignore it would be better to provide a example config file which inlcudes the dummy text and tags.

Additionally the REAMDE.md should be updated to give the tips to rename / duplicate the config.example.php to config.php.

Missing images while trying to backup a larger Trello board

Hi!
I'm trying to backup my trello board that with tons of my artworks, using Apache on Windows.
But some images was missing, although the program has downloaded many of them.
And I found that most of the lost images are created and uploaded before a certain time point, looks like a date from a year or less ago.
Fortunately, there is no text missing.
And I found this problem in some similar Trello-backuping programs like Wekan, There's an (issue) that is a bit close to this situation. This program can backup a Trello board to a local environment, and while I trying to use this one (still on Windows), it has failed downloading some images and those missing things are still before a similar time point.
You can contact me if you need me providing logs or other files.

Trello requires higher HTTP version

I'm not completely sure what happened, but all my Trello scripts suddenly stopped working.

The following error occurs for every request: HTTP request failed! HTTP/1.1 426 Upgrade Required

Download all attachments of all cards

Hey there, great script! I've one more idea:

All uploaded attachments are also in the json API.

Example: https://trello.com/b/83y8zuVk.json

/* $json->cards[0]->attachments[0] */
"attachment": {
"url": "https://trello-attachments.s3.amazonaws.com/54f4242c1debe4c0bb3cde00/54f4243fb66cce518998e054/1c0ef63771af72490c29ff8bee46615e/lorem.txt",
"name": "lorem.txt",
"id": "54f424db5d946f84dfd8ce92"
}

So this feature would be awesome!

E.g. download all attachments to a folder named by the board an the file has the name of the card. Also check on backup the files already downloaded to not download them again and again.


Made an example script here: https://gist.github.com/CodeBrauer/84bce1fdf0ee27e93571

Some projects have 1 board

Hello!

I thought many of us make backups of 1 board in a project.
This usually runs on the production server of the project.

#!/bin/bash
#
# Download a complete board from Trello API.
#
# VERSION       :0.1.0
# DATE          :2019-10-17
# REFS          :https://developers.trello.com/reference#boardsboardid-1

BOARD_ID="$1"
API_KEY="$2"
API_TOKEN="$3"

BOARDS_ALL_QUERY="actions=all&actions_limit=1000&card_attachment_fields=all&cards=all&lists=all&members=all&member_fields=all&card_attachment_fields=all&checklists=all&fields=all"

set -e

test -n "$BOARD_ID"
test -n "$API_KEY"
test -n "$API_TOKEN"

printf -v API_URL 'https://api.trello.com/1/boards/%s?%s&key=%s&token=%s' "$BOARD_ID" "$BOARDS_ALL_QUERY" "$API_KEY" "$API_TOKEN"

wget -q -O "./${BOARD_ID}.json" "$API_URL"

Could be started from a cron job: cd /somewhere && trello-board-backup.sh "board-id" "api-key" "api-token"

Add the Organization name to the Filename

I just discovered this great little script. But it would be even better if it would keep the organization name in the filename. For example:

trello-board-ORGNAME-BOARDNAME.json

In case that it is in the 'My Boards' section, it just could either leave it out or add a 'My-Boards' instead of ORGAME.

Google Drive attachments

Thanks for this tool. It works perfectly... except I discover somehthing with my attachments:

After setting $backup_attachments = true; I am able to download the attachments of my trello boards... An attachment which has the file name "Foto1" is renamed and saved as 5a0469dd27beb6a63a49fdd8-Foto1.jpg and I can open that file in the back up.
However, in my case this only works for "real attachments". The majority of my attachments are Trello-Linked-Attachments to google Drive ([https://help.trello.com/article/796-attaching-documents-with-google-drive]) documents and for them I also get an downloaded output (like 5a0469e403136f25e760b415-Foto2.jpg including a realistic file size) but when opening this file the system tells me the file is corrupt. This is the case for different format (I tried JPG, xlsx, docx, pdf...)

My questions:

  1. do I need to configure something extra to also be able to download the google drive attachments?
    OR (better and preferred)
  2. is there a way to NOT backup google drive attachments? (because for those I already have a backup... and it would reduce my backup storage space drastically)

Thanks a lot

B

application token not resettable by Trello

Hi !

Thank you for this great script !

I am just sharing my practise. As Trello does not currently provides a mechanism to reset the application token, I store it in a password manager, and made the following modification to the config.php :

$application_token = readline ('Application token');

Is it a good practise ? Would you have a better idea ?

Any way to Restore data to Trello?

I can export the JSON, but can't find any way to restore it back.

Googling says it needs to import via API, is there existing code that helps this?

[feature] Board renaming not managed

Once a board title is changed, the script will see it as a totally new one. So it generates both the json file and (eventually) the relative directory with all the attachments inside. A board's ID check would solve this.

HTTP request failed! HTTP/1.1 426 Upgrade Required

Hi,

When running: sudo /usr/bin/php /backups/trello/trello-backup.php I get an error:

PHP Warning:  file_get_contents(https://api.trello.com/1/members/me/boards?&key=xxxxxx&token=xxxxxx): failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required
 in /backups/trello/trello-backup.php on line 53
Error requesting boards - maybe try again later and/or check your internet connection

PHP version:

$ sudo /usr/bin/php -v
PHP 7.0.33-29+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 14 2020 09:09:15) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-29+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

This script used to work fine but I haven't run it for a while so maybe something does need an update. OS ?

HTTP/1.1 426 Upgrade Required

Your first call to the API (by calling file_get_contents against $url_boards is failing for me with HTTP 426. I found this by adding error_reporting(E_ALL) before that call. Is this something that can be fixed on the client side or something that needs to fixed on their servers?

path bug in config.php

For the $path variable to be set correctly the line '$path = dirname(FILE);' has to be commented out in config.php.

Improve error messag if no boards are found

The current message when having no boards is misleading: Error requesting your boards - maybe check your tokens are correct.

Please improve to something like: Number of returned boards is zero (0). Please review your configuration or start by adding a board to your account.

The script fails with cannot find model

The following error is occurring.

in trello-backup/ on master
โ€บ php trello-backup.php

Warning: file_get_contents(https://api.trello.com/1/members/TonyYates/boards?&key=REDACTED&token=REDACTED): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /Users/tony/Code/trello-backup/trello-backup.php on line 36
Error requesting your boards - maybe check your tokens are correct.

Manually entering the url results in Trello returning the following:

model not found

After further investigation this is due to case sensitivity in the username

Backup folder is never created

Currently, if the backup folder does not exist, it will not be created and the script will die with a message:
"Error creating backup dir - directory X is not writeable"

There is mkdir a line below, but it will never be reached if the directory does not exist in the first place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.