3

I have made a script that I am going to call using windows scheduler to back up a Ruby on Rails app I have made.

When I call the command normally in a command window, the output looks like this

C:\Users\admin\Desktop\app>heroku db:pull --confirm app
    Loaded Taps v0.3.23
    Auto-detected local database: postgres://db:[email protected]/app?encoding=utf8
    Warning: Data in the database 'postgres://db:[email protected]/app?encoding=utf8' will be overwritten and
     will not be recoverable.
    Receiving schema
    Schema:          0% |                                          | ETA:  --:--:--
    Schema:         20% |========                                  | ETA:  00:00:21
    Schema:         40% |================                          | ETA:  00:00:18
    Schema:         60% |=========================                 | ETA:  00:00:12
    Schema:         80% |=================================         | ETA:  00:00:05
    Schema:        100% |==========================================| Time: 00:00:29
    Receiving indexes
    schema_migrat:   0% |                                          | ETA:  --:--:--
    schema_migrat: 100% |==========================================| Time: 00:00:05
    users:           0% |                                          | ETA:  --:--:--
    users:          50% |=====================                     | ETA:  00:00:05
    users:         100% |==========================================| Time: 00:00:10
    Receiving data
    5 tables, 1,000 records
    table1: 100% |==========================================| Time: 00:00:00
    table2:         100% |==========================================| Time: 00:00:00
    table3: 100% |==========================================| Time: 00:00:00
    table4:      100% |==========================================| Time: 00:00:00
    table5:      100% |==========================================| Time: 00:00:01
    Resetting sequences 

Here is my .bat:

heroku db:pull --confirm app >> log.txt

If I run this twice, this is the output that goes into a file, log.txt

Loaded Taps v0.3.23
Auto-detected local database: postgres://db:[email protected]/webapp_development?encoding=utf8
Warning: Data in the database 'postgres://db:[email protected]/webapp_development?encoding=utf8' will be overwritten and will not be recoverable.
Receiving schema





Receiving indexes



Receiving data
5 tables, 1,000 records
Resetting sequences

Loaded Taps v0.3.23
Auto-detected local database: postgres://db:[email protected]/webapp_development?encoding=utf8
Warning: Data in the database 'postgres://db:[email protected]/webapp_development?encoding=utf8' will be overwritten and will not be recoverable.
Receiving schema





Receiving indexes



Receiving data
5 tables, 1,000 records
Resetting sequences

Is there any way to include the exact console output, and also include dates and times of when the script was run? Thanks in advance.

UPDATE:

Start: 19/10/2012 12:08:04.90 
                                                                               Schema:          0% |                                          | ETA:  --:--:--Schema:         20% |========                                  | ETA:  00:00:24Schema:         40% |================                          | ETA:  00:00:18Schema:         60% |=========================                 | ETA:  00:00:13Schema:         80% |=================================         | ETA:  00:00:06Schema:        100% |==========================================| ETA:  00:00:00Schema:        100% |==========================================| Time: 00:00:32
                                                                               schema_migrat:   0% |                                          | ETA:  --:--:--schema_migrat: 100% |==========================================| ETA:  00:00:00schema_migrat: 100% |==========================================| Time: 00:00:05
                                                                               users:           0% |                                          | ETA:  --:--:--users:          50% |=====================                     | ETA:  00:00:05users:         100% |==========================================| ETA:  00:00:00users:         100% |==========================================| Time: 00:00:08
                                                                               schema_migrat:   0% |                                          | ETA:  --:--:--schema_migrat:   7% |==                                        | ETA:  00:00:06schema_migrat: 100% |==========================================| Time: 00:00:00
                                                                               users:           0% |                                          | ETA:  --:--:--users:           3% |=                                         | ETA:  00:00:11users:         100% |==========================================| Time: 00:00:00
                                                                               projecttechno:   0% |                                          | ETA:  --:--:--projecttechno:   6% |==                                        | ETA:  00:00:05projecttechno: 100% |==========================================| Time: 00:00:00
                                                                               technols:        0% |                                          | ETA:  --:--:--technols:        7% |==                                        | ETA:  00:00:05technols:      100% |==========================================| Time: 00:00:00
                                                                               projects:        0% |                                          | ETA:  --:--:--projects:        1% |                                          | ETA:  00:00:54projects:      100% |==========================================| Time: 00:00:00
Loaded Taps v0.3.23
Auto-detected local database: postgres://postgres:[email protected]/webapp_development?encoding=utf8
Warning: Data in the database 'postgres://postgres:[email protected]/webapp_development?encoding=utf8' will be overwritten and will not be recoverable.
Receiving schema





Receiving indexes



Receiving data
5 tables, 1,000 records
Resetting sequences

1 Answer 1

4

Adding the date and time is easy using %date% and %time%.

You could try to redirect stderr (2) to stdout (&1), perhaps that will capture the missing output.

echo Start: %date% %time% >>log.txt
heroku db:pull --confirm app >>log.txt 2>&1
echo Stop: %date% %time% >>log.txt
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for helping, seems to be a bit of a problem still. see update
Don't really know how to explain whats going wrong, but I think it's just the formatting of the log file. Can you see any way to fix this?
@Jamie - It looks like heroku modifies the position on the screen as it prints status information to stderr. I don't think it is possible to get a good looking log without a ridiculous amount of work. I would keep the ugly log or else revert back to your original log without the stderr. If absolutely necessary you could redirect stderr to another file and then process and extract required info from it and then append to the regular log, but I wouldn't know what you would need. It could be tricky depending on what you try to extract.
Ok thanks. I will probably revert back to my old log but include the dates. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.