Delete 
 
 
#linux #sysadmin #bash #script #es #elasticsearch #DELETE #purge
  elasticsearch indexes older than 1 month:#!/bin/bash
last_month=`date +%Y%m%d --date '1 month ago'`
old_es_index="faxplus_*-$last_month"
echo "Deleting ES indexes $old_es_index..."
curl -X DELETE 'http://localhost:9200/myindex_*-20180520'
echo ''
NOTE: asterisk in curl command will be anything in between of myindex_ and -20180520. For example myindex_module1-20180520.#linux #sysadmin #bash #script #es #elasticsearch #DELETE #purge
Get specific date like 2 days ago by bash script:
 
#linux #date #bash_script #bash
  #!/bin/bash
specific_date=`date --date="3 day ago" +%Y%m%d`
echo $specific_date
#linux #date #bash_script #bash
https://unix.stackexchange.com/questions/31414/how-can-i-pass-a-command-line-argument-into-a-shell-script
#shell #argument #pass_argument #command_line #terminal #linux #bash #script
  
  #shell #argument #pass_argument #command_line #terminal #linux #bash #script
Unix & Linux Stack Exchange
  
  How can I pass a command line argument into a shell script?
  I know that shell scripts just run commands as if they were executed in at the command prompt.  I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or
  https://dba.stackexchange.com/questions/41050/is-it-safe-to-delete-mysql-bin-files
#mysql #mysql_bin #bin #bin_file #purge
  
  #mysql #mysql_bin #bin #bin_file #purge
Database Administrators Stack Exchange
  
  Is it safe to delete mysql-bin files?
  I have MM Replication in mysql, and I want to squeeze some free space in the box be deleting unnecessary files, I came across these mysql-bin files inside /var/db/mysql/ There are hundreds of those...
  Write pandas dataframe into Google bigQuery:
https://pandas.pydata.org/pandas-docs/version/0.21/generated/pandas.DataFrame.to_gbq.html#pandas-dataframe-to-gbq
#pandas #bg #bigquery
  https://pandas.pydata.org/pandas-docs/version/0.21/generated/pandas.DataFrame.to_gbq.html#pandas-dataframe-to-gbq
#pandas #bg #bigquery
Months ago we have talked about how to get mongoDB data changes. THe problem with that article was that if for any reason your script
was stopped you will lose the data in the downtime period.
Now we have a new solution that you will read from the point in time that have read last time. MongoDB uses bson Timestamp in order for its internal usage like replication oplog logs. We can use the same Timestamp and store it somewhere to read from the exact point
that we have read last time.
In python you can import it like below:
 
Now to read data from that point read that time stamp from where you have saved it and query the oplog from that point:
 
After traversing cursors and catching mongoDB changes you can store the new timestamp that resides in
Now use a
If you remember from before we got last changes by the query below:
 
We read the last ts and read from the last record, that's why we were missing data.
#mongodb #mongo #replication #oplog #timestamp #cursor
  was stopped you will lose the data in the downtime period.
Now we have a new solution that you will read from the point in time that have read last time. MongoDB uses bson Timestamp in order for its internal usage like replication oplog logs. We can use the same Timestamp and store it somewhere to read from the exact point
that we have read last time.
In python you can import it like below:
from bson.timestamp import Timestamp
Now to read data from that point read that time stamp from where you have saved it and query the oplog from that point:
ts = YOUR_TIMESTAMP_HERE
cursor = oplog.find({'ts': {'$gt': ts}},
cursor_type=pymongo.CursorType.TAILABLE_AWAIT,
oplog_replay=True)
After traversing cursors and catching mongoDB changes you can store the new timestamp that resides in
ts field in the document you   have fetched from MongoDB oplog.Now use a
while True and read data until cursor is alive. The point of this post is that you can store ts somewhere and read from    the point you have stored ts.If you remember from before we got last changes by the query below:
last = oplog.find().sort('$natural', pymongo.DESCENDING).limit(1).next()
 ts = last['ts']We read the last ts and read from the last record, that's why we were missing data.
#mongodb #mongo #replication #oplog #timestamp #cursor
There is always a risk and also a problem when altering a production mySQL table. 
Installation steps on Debian:
1- wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
2- sudo dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
3- sudo apt-get update
4- sudo apt-get install percona-toolkit
Now you have percona toolkit on your Debian server. Use the command
#mysql #percona #schema #alter_table #online_schema_change #percona_toolkit #pt_online_schema_change
  Percona has released a toolkit that contains a command called pt-online-schema-change. It will change table schema live on production without downtime.Installation steps on Debian:
1- wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
2- sudo dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
3- sudo apt-get update
4- sudo apt-get install percona-toolkit
Now you have percona toolkit on your Debian server. Use the command
pt-online-schema-change for your table alteration.#mysql #percona #schema #alter_table #online_schema_change #percona_toolkit #pt_online_schema_change
In order to dry run before the real execution use 
 
Now after dry run you can execute the alter command:
 
#mysql #percona #schema #alter_table #online_schema_change #percona_toolkit #pt_online_schema_change
  --dry-run:pt-online-schema-change --dry-run h=127.0.0.1,D=YOUR_DB,t=YOUR_TABLE --alter "ADD COLUMN (foobar varchar(30) DEFAULT NULL);"
Now after dry run you can execute the alter command:
pt-online-schema-change --execute h=127.0.0.1,D=YOUR_DB,t=YOUR_TABLE --alter "ADD COLUMN (foobar varchar(30) DEFAULT NULL);"
#mysql #percona #schema #alter_table #online_schema_change #percona_toolkit #pt_online_schema_change
https://dba.stackexchange.com/questions/187630/problem-with-aborted-pt-online-schema-change-command
#mysql #trigger #percona #online_schema_change
  
  #mysql #trigger #percona #online_schema_change
Database Administrators Stack Exchange
  
  Problem with aborted PT-online-schema change command
  I aborted a pt-online-schema change command to change a table definition. Now, when I run pt-online-schema change again, I get this error: 
The table . has trigge...
  The table . has trigge...
  Tech C**P
https://dba.stackexchange.com/questions/187630/problem-with-aborted-pt-online-schema-change-command  #mysql #trigger #percona #online_schema_change
In order to add multiple columns in alter table command use ONE 
#percona
  --alter and comma separate ADD COLUMNS statements.#percona
Do you think 
Its security is like shell, as it uses shell authentication mechanism for login. You need to open UDP ports 60000 to 61000. Or you can give
 
One of the caveats of mosh is that you cannot scroll to previous commands as its buffer is limited to the window you are viewing itself.
Install it using
For further instruction head over to link below:
 
#ssh #mosh #terminal
  SSH sucks? Do you think SSH suck specially when you are from an unstable network like what we have in IRAN and when DPI (Deep Packet Inspection) is undergo? OK, I have mosh for you. mosh stands for Mobile Shell. It reconnects itself and you never   have to login again. Even if you change your internet connection you are safe and your shell is open :)Its security is like shell, as it uses shell authentication mechanism for login. You need to open UDP ports 60000 to 61000. Or you can give
-p parameter to connect on a specific port:mosh -p 60010 admin@my_server.com
One of the caveats of mosh is that you cannot scroll to previous commands as its buffer is limited to the window you are viewing itself.
Install it using
apt-get install mosh.For further instruction head over to link below:
https://mosh.org/
#ssh #mosh #terminal
To test 
#mosh #test #reconnect
  mosh, disconnect from internet while you're logged into your server and now wait for a message from mosh that says you last connected to server 10 secs ago, etc. Now connect to internet again. Voila! You're back again. This is amazing :))))#mosh #test #reconnect
In order to get a random document from MongoDB collection you can use aggregate framework:
 
 
Read more here: https://www.mongodb.com/blog/post/how-to-perform-random-queries-on-mongodb
This method is the fastest and most efficient way of getting random data from a huge database like 100 M records.
#mongodb #mongo #aggregate #sample #random
  
  db.users.aggregate(    [ { $sample: { size: 1 } } ] )NOTE: MongoDB 3.2 introduced $sample to the aggregation pipeline.Read more here: https://www.mongodb.com/blog/post/how-to-perform-random-queries-on-mongodb
This method is the fastest and most efficient way of getting random data from a huge database like 100 M records.
#mongodb #mongo #aggregate #sample #random
MongoDB
  
  How to Perform Random Queries on MongoDB | MongoDB Blog
  
  in 
most important part if this scenario is when you are using micro service architecture and you have tens of modules which works independently from each other and send their requests to
 
Now if you look at the MongoDB log you would see:
 
In the above log you would see
#mongodb #mongo #pymongo #appname
  pymongo you can give name to your connections. This definitely helps to debug issues or trace logs when seeing mongoDB logs. Themost important part if this scenario is when you are using micro service architecture and you have tens of modules which works independently from each other and send their requests to
MongoDB:mc = pymongo.MongoClient(host, port, appname='YOUR_APP_NAME')
Now if you look at the MongoDB log you would see:
I COMMAND  [conn173140] command MY_DB.users appName: "YOUR_APP_NAME" command: find { find: "deleted_users", filter: {}, sort: {        acquired_date: 1 }, skip: 19973, limit: 1000, $readPreference: { mode: "secondaryPreferred" }, $db: "blahblah" } planSummary:          COLLSCAN keysExamined:0 docsExamined:19973 hasSortStage:1 cursorExhausted:1 numYields:312 nreturned:0 reslen:235 locks:{ Global: {     acquireCount: { r: 626 } }, Database: { acquireCount: { r: 313 } }, Collection: { acquireCount: { r: 313 } } } protocol:op_query 153msIn the above log you would see
YOUR_APP_NAME.#mongodb #mongo #pymongo #appname
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project#flask-limiter
#flask #rate_limiter #mail #celery
  
  #flask #rate_limiter #mail #celery
Nick Janetakis
  
  15 Useful Flask Extensions and Libraries That I Use in Every Project — Nick Janetakis
  Part of the benefit of using a popular web framework is the thriving community around it. Here's my favorite Flask extensions.