Saturday, April 11, 2020

Crons stopped working

Error : cron[26468]: (root) INSECURE MODE (mode 0600 expected) (crontabs/root)

If your crons have stopped working because of incorrect permissions, here is the solution for you.

Solution :
sudo chmod 600 /var/spool/cron/crontabs/root
sudo service cron restart

Odoo Create database from UI error

Database creation error: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template.

If you get the above error while creating database from Odoo database manager or if you are creating a new database in postgresql but its Encoding is SQL_ASCII and Collate & Ctype is C.

here is the solution for you.

You need to run following queries as a postgresql administrator.

update pg_database set datallowconn = TRUE where datname = 'template0';

\c template0

update pg_database set datistemplate = FALSE where datname = 'template1';

drop database template1;

create database template1 with encoding = 'UTF-8' lc_collate = 'en_US.UTF8' lc_ctype = 'en_US.UTF8' template = template0;

update pg_database set datistemplate = TRUE where datname = 'template1';

\c template1

update pg_database set datallowconn = FALSE where datname = 'template0';

\q

After running these queries, you will be able to create database from Odoo database manager without any error as well as your new created database in postgresql has Encoding UTF8 and Collate & Ctype will be en_US.UTF-8.

Wednesday, March 4, 2020

Upload file on Google Drive using shell script

If you want to send backup files like sql on google drive regularly using an automated script, here is the solution for you.

1. First clone following repository from github.
git clone https://github.com/labbots/google-drive-upload.git
2. Now run following commands.
cd google-drive-upload
./google-oauth2.sh
It will ask you to add Client ID and Secret Key of your google account. To generate access key and secret key of google drive Open link https://console.developers.google.com/apis/credentials
Create Credentials > Oauth Client ID > Other > Create
Now Copy client ID and secret Key and use in your script. If it gives 403 restricted access then go to OAuth consent screen and create a project to generate client ID and secret Key.

3. Now Enter Client ID and Secret Key. It will be stored in ~/googledrive.conf To copy file on google drive, run command
sudo ./upload.sh -v -r 1zfZKk37SgPFc4k_sbAVI_Xo9U427X3KU databasefile.sql.zip
1zfZKk37SgPFc4k_sbAVI_Xo9U427X3KU is your drive foldername which you can find in url and where you want to copy the file.

4. Now you get a url of devices with a code, you need to hit the url in browser and submit the code. 

Now this device has access to upload file on google drive. Addig code is one time activity, once your google account knows about the device, it will not ask to enter code again and that's why you can create shell script and add it in cron to take regular backup automatically.

Note : 
If you have set up the cron but file is not transferred on google drive, although it is transferred using same script when you run the script manually, there may be one issue, you have set up the cron for root user. Root user is unable to find .googledrive.conf in its home directory but when you run the script manually, you may use sudo but still the user who is running the script is not root, so it is able to find .googlefrive.conf in its home directory.

To fix this issue, set up the cron for the user who configured googledrive or copy the .googledrive.conf file in root's home directory. This should solve the issue.